我必须在表格中显示 2 个不同的单元格。我已经通过将原型(prototype)设置为表格来尝试过。但它仍然显示 Prototype table cells must have reuse identifiers
警告。
有人可以指导我解决此警告。
点击此链接: UITableview with more than One Custom Cells with Swift
最佳答案
在 Storyboard 中,您必须为单元格定义标识符,如下图
然后在 cellForRowAtIndexPath
中,您必须像这样为特定的单元格使用特定的标识符
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Identifier1")
//set the data here
return cell
}
else if indexPath.row == 1 {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Identifier2")
//set the data here
return cell
}
}
关于ios - 如何在 UITableView 中显示 2 个自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39515763/