ios - 在 Swift 中创建 UITableView 对象时崩溃

标签 ios uitableview swift

我正在 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/

相关文章:

ios - Segue传递数据后如何重新加载tableView数据

ios - 主 - 详细项目未按预期工作

swift - 什么时候使用UIView动画,CABasicAnimation和UIViewPropertyAnimator?

ios - 设备上令人沮丧的 EXC_BAD_ACCESS(NSData/OpenGL 相关?) - 在模拟器上工作正常

ios - 使用 MPMediaPlayer Swift 4 淡入淡出(动画)音量

ios - 如何删除我的 NSString 中带有括号 () 的任何子字符串?

ios - xcode 签名无效包含不允许的权利 ios 中的错误

ios - 重用时 UICollectionViewCell 子类中的倒计时逻辑

ios - 下载每个图像后重新加载 tableview

swift - 如何使用自定义 token 根据 firebase 中的用户名验证用户?