繁体   English   中英

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

[英]Not able to jump from tableViewCell to another viewController using segue

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

使用情节提要Segue

我也尝试以编程方式使用以下代码:-

 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!)

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

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

(为什么单元连接不能自动工作,我不知道。)

我将其修复如下:

 //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。

故事板屏幕

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM