![](/img/trans.png)
[英]NSFetchResultsController, populate new data into the table view
[英]Unable to populate data into table view
这是Swift4。我无法将数据(在信息数组中)填充到表视图中。 我期望在表视图中显示字符串“名称”,“出生日期”,“性别”,“电话”,“电子邮件”,但是什么都没有显示。
我已经输入“ ProfileInfo”作为tableViewCell标识符。
谢谢。
let information = ["Name", "Date of Birth", "Gender", "Phone", "Email"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return information.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileInfo", for: indexPath) as! OTProfileTableViewCell
cell.label.text = information[indexPath.row]
return cell
}
OP未包含某些内容。 我假设您使用的是UIViewController
子类,并将UITableView
作为子视图(因为表上方有另一个视图,而使用UITableViewController
则不那么简单)。
如果尚未完成以下操作,请尝试以下操作:
tableView.dataSource
。 您可以在viewDidLoad
或界面构建器中进行设置。 是否正在调用tableView(_:cellForRowAt:)
,并且您要获取的单元格类型正确? 在此方法中使用断点进行检查。 如果未达到断点,则可能无法正确设置表的数据源。
还要在tableView(_:numberOfRowsInSection:)
设置一个断点。 该方法应始终执行(只要您至少有1个部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.