2016-10-04 77 views
-1

問題:image of UITableViewCells that never display data without being selected.UITableView的數據顯示古怪SWIFT 3.0

的問題是一致的就好了,即使禁止用戶觸摸交互仍然造成這一問題的出現。行應該有3個子行,但只顯示該部分的結尾(連同標題一樣,如圖中所示)。

此表視圖代碼:

import UIKit 

class HistoryViewController : UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet var tableview: UITableView! 

    var data = LocalizedData.localizedData 
    let cellReuseIdentifier = "tableCell" 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     tableview.delegate = self 
     tableview.dataSource = self 
     //tableview.allowsSelection = true 
     tableview.allowsMultipleSelection = true 

     if AppDelegate.debug { 
      print("HistoryViewLoaded") 
     } 
    } 

    override func viewDidAppear(_ animated: Bool) { 
     super.viewDidAppear(animated) 

     tableview.reloadData() 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section:Int) -> Int { 
     return data.getMatchDataCount() 
    } 

    func tableView(_ tableView:UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! HistoryViewTableCell 

     if !AppDelegate.device.isEqual(to: 4.0) { 
      cell.textLabel?.text = "Entry " + (indexPath.item + 1).description 
     } 

     if data.getMatchDataCount() > 0 { 
      cell.matchNumb?.text = data.getMatchTest(matchNumber: indexPath.item)[1].description 
      cell.teamNumb?.text = data.getMatchTest(matchNumber:indexPath.item)[0].description 
     } 

     return cell 
    } 
} 

class HistoryViewTableCell: UITableViewCell { 

    @IBOutlet weak var teamNumb: UILabel! 
    @IBOutlet weak var matchNumb: UILabel! 
    @IBOutlet weak var matchPoints: UILabel! 

} 

回答

0

你應該嘗試打印teamNumb & matchNumb的框架,根據它看起來像標籤是在這裏,但有一定的佈局問題上的圖片。

print(matchNumb.frame) 
print(teamNumb.frame) 

而且你的代碼在雨燕2.2,雨燕2.3或之前?

我有一個類似的問題,我的單元格在'cellForRowAt'函數中沒有生成動畫,因爲我將我的項目轉換爲Swift 3,而我派遣到主要修復它。 想到當我調試時,這行已經在主線程中。

我想你可以嘗試:

DispatchQueue.main.async { 
    // Set cell.numb.text here.. 
} 
+0

我居然發現,在斯威夫特3和Xcode中8,表標題是導致該問題。我不完全確定它爲什麼只在運行時發生,並且在實際編輯過程中從未出現過,但是我避免使用表標題作爲當前配置(iOS 10,Swift 3和Xcode 8)。 – Austin