[英]Swift custom table cell
我一直在嘗試在我的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的單元出隊-必須為該標識符注冊一個筆尖或一個類,或者在情節提要中連接原型單元
這是什么意思?
在情節提要中,選擇tableView單元,然后在屬性檢查器中將標識符設置為“ SimpleTableItem”。 希望這可以幫助
dequeueReusableCellWithIdentifier
試圖查找標識符為"SimpleTableItem"
的單元格,但似乎您沒有在任何地方給該單元格指定該標識符。 一種方法是在情節提要的“表視圖”中選擇一個單元格,轉到“屬性”檢查器並將其標識符設置為SimpleTableItem
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.