UITableVIewCell错误Xcode 7/Swift 2

yze*_*t00 15 uitableview ios swift xcode7 swift2

我在此代码中遇到以下错误:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
Run Code Online (Sandbox Code Playgroud)

错误:来自'UITableViewCell?'的沮丧?'UITableViewCell'只展开选项; 你的意思是用'!'?

有任何想法吗?

Lon*_*ham 30

Swift2.0方法dequeueReusableCellWithIdentifier是声明为:

@available(iOS 6.0, *)
func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> UITableViewCell
Run Code Online (Sandbox Code Playgroud)

你不应该投UITableViewCellUITableViewCell?.见下面的代码.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

    // Configure the cell...

    return cell
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!