简体   繁体   中英

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:-

使用情节提要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.

Moreover,below segue method is never called.

 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. 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. (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.

(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. In below I have provided navigation controller with storyboard id.

故事板屏幕

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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