像这样的 TableView 问题:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellReuseIdentifier = "cell"
let cell: UITableViewCell = autoCompleteTableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier, forIndexPath: indexPath) as UITableViewCell
let index = indexPath.row as Int
cell.textLabel!.text = tableArray[index]
return cell
}
当我运行该应用程序时,我得到:“无法使具有标识符 cell 的单元格出列 - 必须为标识符注册一个 nib 或一个类,或者在 Storyboard中连接一个原型(prototype)单元格”
。我在这里做错了什么?
编辑:
我没有为这个 UITableView 使用 Storyboard
最佳答案
如果您不使用 Storyboard,则可以使用您的 cellIdentifier 创建默认的 UITableViewCell:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
此代码尝试查找具有给定标识符的 UITableViewCell
。如果不这样做,它会使用给定的标识符创建一个新的 UITableViewCell
并将其添加到 UITableView
。
关于ios - 无法使单元格出队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432675/