2016-02-23 193 views
0

我一直試圖在我的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 - 必須爲標識符註冊一個筆尖或類,或連接故事板中的原型單元格

這是什麼意思?

+1

運行時詢問您「SimpleTableItem」是什麼。故事板中沒有這樣的單元格,並且您沒有將它與任何筆尖相關聯,所以它應該從哪裏來? – matt

+0

你在viewDidLoad中註冊了嗎?例如:'tableView.registerClass(SimpleTableItem.self,forCellReuseIdentifier:NSStringFromClass(SimpleTableItem))' – AtheistP3ace

回答

0

在故事板中,選擇您的tableView單元格,並在屬性檢查器中將標識符設置爲「SimpleTableItem」。希望這可以幫助

0

dequeueReusableCellWithIdentifier正在嘗試查找標識爲"SimpleTableItem"的單元,但似乎您沒有在任何地方給過標識。一種方法是在故事板中的表視圖中選擇一個單元格,轉到屬性檢查器並將其標識符設置爲SimpleTableItem