我一直試圖在我的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