【问题标题】:Cannot display another ViewController when TableView cell is selected选择 TableView 单元格时无法显示另一个 ViewController
【发布时间】:2016-05-23 02:51:53
【问题描述】:

当我的 TableView 中的一个单元格被选中时,我想显示一个新的 ViewController(故事板 ID:TaskDetailsVC)。这是我的 TableView 代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    displayTask.deselectRowAtIndexPath(indexPath, animated: true)
    let row = Tasks.sharedInstance.datas[indexPath.row]
    print(row)
    let TaskDetailsVC = self.storyboard!.instantiateViewControllerWithIdentifier("TaskDetailsVC") as! TaskDetailsViewController
    self.navigationController!.pushViewController(TaskDetailsVC, animated: true)
}

我可以在每行的右上角看到一个箭头,但是当我单击单元格时没有任何反应。我该如何解决?

我的 ViewController 代码可以在这里找到https://codeshare.io/C4uNh

【问题讨论】:

  • 当你点击单元格时,这个didSelectRowAtIndexPath函数会被调用吗?表视图的委托设置了吗?
  • didSelectRowAtIndexPath 函数中设置断点并检查它是否被调用?
  • 检查您当前的控制器父类/超类是否为 UINavigationController?
  • @Phuc 好像没有调用..你知道修复它吗?
  • @Pavan 我该怎么做?

标签: ios uitableview swift2


【解决方案1】:

在 viewDidLoad 方法中添加以下行

 displayTask.delegate = self

【讨论】:

    【解决方案2】:

    我认为您的代表没有设置!右键单击情节提要并查看它是否设置或您的 IBOutlet 设置不正确

    【讨论】:

      【解决方案3】:

      添加以下内容:-

      displayTask.delegate = self
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-25
        • 1970-01-01
        相关资源
        最近更新 更多