Swift Table View Controller Segue 未自动运行

Swift Table View Controller Segue Not Working Automatically

采取的步骤:

  1. 创建了新的单视图项目
  2. 已删除默认视图控制器
  3. 添加了新的Table视图控制器
  4. 将 TVC 嵌入到导航控制器中
  5. 添加了 child TVC
  6. 添加了自定义 class 文件并关联到每个 TVC
  7. 创建了从第一个 TVC 到 child
  8. 的节目转场
  9. 实现了所需的方法,#of sections,#of rows,cellForRowAtIndexPath

我在网上观看和阅读的所有教程都只包括我上面显示的步骤,并且 segues 开始工作正常。但是,就我而言,在添加以下内容之前我无法让它工作:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        performSegueWithIdentifier("detail", sender: tableView)
}

如果需要,我完全可以实现 didSelectRowAtIndexPath 方法。我只是想知道我是否遗漏了什么,因为它似乎在我在网上看到的所有内容中自动运行。

提前致谢!

如果您单击 segue(情节提要)和侧面菜单,您必须从

分配文本 "detail"
performSegueWithIdentifier("detail", sender: tableView)

标识符 字段上。

喜欢下图

编辑:

尝试上面的代码,记得将 NAME_OF_THE_DETAIL_VIEW_CONTROLLER 更改为您的详细信息 ViewController。

在这段代码中,我们在 performSegueWithIdentifier 之前设置了“self”。单击按钮后,您将 segue.destinationViewController 设置为新的 ViewController.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("detail", sender: indexPath);
}


override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "detail") {
        var detailView =  segue.destinationViewController as! NAME_OF_THE_DETAIL_VIEW_CONTROLLER 
    }
}

感谢大家的贡献。我发现问题是 cellForRowAtIndexPath tableView 函数中缺少以下内容。

let cell = self.tableView.dequeueReusableCellWithIdentifier("custom", forIndexPath: indexPath) as! CustomCell

我把这行注释掉了,主要是因为我不知道它的作用。 :)