我正在 Swift 中制作一个待办事项应用程序,并尝试使用 UITableView 显示任务。用户添加任务,然后按“完成”。 UITableView 返回到前面,应用程序崩溃。这是我的代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: nil) //crashes on this line
cell.textLabel!.text = taskMgr.tasksArray[indexPath.row].name
cell.detailTextLabel!.text = taskMgr.tasksArray[indexPath.row].desc
return cell
}
有趣的是,这条线在我快速创建的另一个非常相似的应用程序中运行良好。有人能指出我正确的方向吗?如有必要,我很乐意添加更多详细信息。
最佳答案
我是这样写的:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:CustomCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell
cell.lblText.text = "Testing"
return cell
}
关于ios - 在 Swift 中创建 UITableView 对象时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30115526/