将“UITableViewCell”types的值转换为自定义单元格

我通常从来没有这个步骤的问题,但由于某种原因,当我重新设置我的故事板现在我有这个部分的代码问题:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell (cell as! TableViewCell).usernameLabel.text = friendsArray[indexPath.row] as String return cell } 

我已经做了所有的明显的东西,如确保单元格标识符是“单元格”。

我的错误是这样的:

无法将types“UITableViewCell”(0x1094ada18)的值转换为“YOpub.TableViewCell”(0x106620410)。

编辑:问题是我有我的didLoad函数self.tableView.registerClass(UITableViewCell.self,forCellReuseIdentifier:“单元格”)。 删除这一行后,我的代码再次工作。

  • 你可能忘记告诉故事板,这个单元格一个TableViewCell。 select原型单元格,并在“身份”检查器中设置“自定义类”。

  • 你可能调用了registerClass:forCellReuseIdentifier: 如果是,请删除该呼叫; 它实际上阻止我们从故事板中获取单元格。

  • 你正在调用tableView.dequeueReusableCellWithIdentifier 。 这是一个很大的错误。 你应该调用tableView.dequeueReusableCellWithIdentifier:forIndexPath:

其中一个原因,可能是在身份检查员模块是不同的,那么你的项目名称。 在这里输入图像说明