我一直试图在我的swift应用程序中使用自定义表格单元格,并遇到了一个问题:当我运行我的应用程序时,我的应用程序崩溃。Swift自定义表格单元格
我的自定义的表格单元格类是SimpleTableCell(Objective-C类)
和我cellForRowAtIndexPath
方法(SWIFT)是:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("SimpleTableItem", forIndexPath: indexPath)
let data = TableData[indexPath.row]
cell.textLabel?.text = data.description
if (data.image == nil)
{
cell.imageView?.image = UIImage(named:"image.jpg")
load_image(image_base_url + data.imageurl!, imageview: cell.imageView!, index: indexPath.row)
}
else
{
cell.imageView?.image = TableData[indexPath.row].image
}
return cell
}
我的应用程序崩溃与错误: 无法出列单元格带标识符SimpleTableItem - 必须为标识符注册一个笔尖或类,或连接故事板中的原型单元格
这是什么意思?
运行时询问您“SimpleTableItem”是什么。故事板中没有这样的单元格,并且您没有将它与任何笔尖相关联,所以它应该从哪里来? – matt
你在viewDidLoad中注册了吗?例如:'tableView.registerClass(SimpleTableItem.self,forCellReuseIdentifier:NSStringFromClass(SimpleTableItem))' – AtheistP3ace