繁体   English   中英

无法将数据填充到表格视图中

[英]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则不那么简单)。

如果尚未完成以下操作,请尝试以下操作:

  1. 确保将视图控制器分配为tableView.dataSource 您可以在viewDidLoad或界面构建器中进行设置。
  2. 在视图控制器中声明对UITableViewDataSource协议的符合性。 优选地,在包含协议的所有必需方法的实现的扩展中。

是否正在调用tableView(_:cellForRowAt:) ,并且您要获取的单元格类型正确? 在此方法中使用断点进行检查。 如果未达到断点,则可能无法正确设置表的数据源。

还要在tableView(_:numberOfRowsInSection:)设置一个断点。 该方法应始终执行(只要您至少有1个部分)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM