2016-10-04 75 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