无法使用segue从uitableViewCell跳转到另一个viewController

时间:2014-09-22 12:04:17

标签: ios uitableview swift xcode6

嗨,我是swift和Xcode 6的新手,所以我尝试执行segue从单元格跳转到另一个viewController,如下所示: -

Segue using storyboard

此外,我尝试使用以下代码进行编程: -

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    println("selected row \(indexPath.row)")
    self.performSegueWithIdentifier("segueCust", sender: self)
}

我仍然无法执行,如果在代码上方运行,那么应用程序崩溃并出现以下错误: -

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<swiftDemo.DetailTableViewController: 0x7fdab1606ee0>) has no segue with identifier 'segueCust''

不知道为什么会出现这个错误,因为在故事板中我已经为segue分配了这个标识符。

此外,永远不会调用以下segue方法。

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)

此外,我添加了一个按钮,并使用storyboard从一个viewController到另一个viewController执行segue,然后它正常工作。 到目前为止,我可能会失踪或犯下一个愚蠢的错误。任何帮助,将不胜感激。 提前谢谢。

2 个答案:

答案 0 :(得分:0)

如果要以编程方式使用self.performSegueWithIdentifier调用segue,则需要从视图控制器本身链接。 (那是self在您的代码中的含义。)从您的图像中,您似乎将其连接到单元格而不是视图控制器。

(为什么单元格连接不会自动生效,我不知道。)

答案 1 :(得分:0)

我修好了如下: -

 //Embedded my tableVC with navigationController and provided that navigationController a storyboard id.
 //Used that navigationController and presented it on my current VC as below.
 var storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            var vc : UINavigationController = storyboard.instantiateViewControllerWithIdentifier("naviVC") as UINavigationController

 self.presentViewController(vc, animated: true, completion: nil)

还将我的tableView单元与另一个VC连接(如下所示),并且应该可以顺利运行。 在下面我提供了带故事板id的导航控制器。

Storyboad screenShot

相关问题