缺少函数错误返回 - Swift Xcode

时间:2016-01-13 22:59:54

标签: ios swift

我对swift非常新,这个错误不断涌现。

它说missing return in a function expected to return in UITableViewCell

代码: My Code

任何帮助......非常感谢

1 个答案:

答案 0 :(得分:1)

您需要声明一个单元格。标识符是您在Storyboard中添加的标识符,我的标识符为#34; Cell"在这个例子中。

let cell: UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

设置单元格属性,例如

cell.textLabel.text = "Test"

然后返回单元格

return cell

此方法返回给定路径的单元格,因此这是您为单元格添加信息的部分。阅读熟悉UITableView类的documentation

func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        let cell: UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
        cell.textLabel.text = "Test
        return cell
    }
相关问题