-2

我正在使用 swift 构建一个应用程序,并创建了一个在表格视图中显示超过 700 行的数组。问题是我需要每一行占据它自己的单个单元格,但是所有 700 个文本字符串都被分组到一个表格视图单元格中。如何在不手动创建和标记 700 多个新 tableviewcells 的情况下将每个字符串分隔到自己的单元格?

编辑:感谢您的帮助!看来我真的不明白表格视图是如何工作的。我现在已经制作了自定义 tableviewcells,并且应该得到我正在寻找的结果。

4

1 回答 1

0

假设你有你的数组let myData = ["item 1", "item 2", "item 3"]

确保你的UIViewController继承UITableViewDataSource

覆盖以下方法并进行相应修改

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return myData.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // Should ideally get UITableViewCell using dequeueReusableCellWithIdentifier
    var cell = UITableViewCell()
    cell.textLabel?.text = myData[indexPath.row]
    return cell
}
于 2015-05-26T23:41:36.230 回答