Swift自定义表格单元格

时间:2016-02-23 17:44:34

标签: ios 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对单元格出列 - 必须为标识符注册nib或类或在故事板中连接原型单元格

这是什么意思?

2 个答案:

答案 0 :(得分:0)

在故事板中,选择tableView单元格,然后在属性检查器中,将标识符设置为" SimpleTableItem"。希望这有帮助

答案 1 :(得分:0)

dequeueReusableCellWithIdentifier正在尝试查找标识为"SimpleTableItem"的单元格,但似乎您没有在任何地方为该标识符提供单元格。一种方法是在Storyboard的Table View中选择一个单元格,转到Attributes Inspector并将其标识符设置为SimpleTableItem

相关问题