2016-02-23 197 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