简体   繁体   English

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

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

Hi I'm new to swift and Xcode 6 so I tried to perform the segue to jump from cell to another viewController shown as below:- 嗨,我是swift和Xcode 6的新手,所以我尝试执行segue从单元格跳转到另一个viewController,如下所示:-

使用情节提要Segue

Also I tried to go programmatically with below code:- 我也尝试以编程方式使用以下代码:-

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

Still I'm not able to perform and if run above code then app crash with following error:- 仍然无法执行,如果在上述代码上运行,则应用崩溃,并显示以下错误:-

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

No idea why this error is coming as in storyboard I have assigned the segue with this identifier. 不知道为什么会出现此错误,因为在情节提要中我已为segue分配了此标识符。

Moreover,below segue method is never called. 而且,永远不会调用以下segue方法。

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

Also I have add a button and perform segue using storyboard from one viewController to another then it's working fine. 另外,我添加了一个按钮,并使用情节提要从一个viewController到另一个viewController执行segue,然后工作正常。 So far I might be missing or doing a silly mistake. 到目前为止,我可能会丢失或犯一个愚蠢的错误。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks in advance. 提前致谢。

If you want to invoke the segue programmatically with self.performSegueWithIdentifier , it needs to be linked from the view controller itself. 如果要使用self.performSegueWithIdentifier以编程方式调用segue,则需要从视图控制器本身进行链接。 (That's what self is in your code.) From your image, you seem to have it connected to the cell rather than the view controller. (这就是代码中的self 。)从您的图像看来,您似乎已将其连接到单元而不是视图控制器。

(Why the cell connection isn't working automatically, I have no idea.) (为什么单元连接不能自动工作,我不知道。)

I got it fixed as below:- 我将其修复如下:

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

Also connected my tableView cell with another VC(shown below) and rest worked smoothly as it should be. 还将我的tableView单元格与另一个VC(如下所示)连接,其余部分应按预期顺利进行。 In below I have provided navigation controller with storyboard id. 在下面,我为导航控制器提供了情节提要ID。

故事板屏幕

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

相关问题 如何从自定义 TableViewCell 转到另一个 ViewController (Swift) - How to Segue from Custom TableViewCell to Another ViewController (Swift) 正确地从 tableviewcell 内的 collectionview 转到另一个 viewcontroller - Properly segue from collectionview inside tableviewcell to another viewcontroller 从TableViewCell跳转到NavigationController中嵌入的ViewController - Jump from a TableViewCell to a ViewController embedded in a NavigationController 从UITableViewCell到另一个ViewController - Segue from UITableViewCell to another ViewController 从TableViewCell NIB到ViewController的Segue-请看一下 - Segue from TableViewCell NIB to ViewController - Pls have a look 使用segue将Int从一个ViewController传递到另一个 - passing an Int from one ViewController to another using a segue 将数据(标签)从TableViewCell传递到另一个ViewController - Pass Data (Label) from TableViewCell to another ViewController 将数据从 tableviewcell 传递到另一个 viewcontroller - Passing data from tableviewcell to another viewcontroller 将数据从静态 tableViewCell 传递到另一个 viewController? - Passing data from a static tableViewCell to another viewController? 查找数据并将数据从ViewController传输到另一个ViewController - segue and transfer data from viewcontroller to viewcontroller to another viewcontroller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM