简体   繁体   中英

Specify which viewController is pushed by segue?

Is there anyway to programatically control which viewController is pushed into view when a segue us selected? What I want to do is segue to one of two controllers when a UITableViewCell is tapped, one for iPhone4 (960 height) and the other iPhone5 (1136 height).

I could just layout/arrange a single view controller manually to accommodate the extra height. Or I could add a 2nd segue (with another ID) and then use -tableView:didSelectRowAtIndexPath: in conjunction with -performSegueWithIdentifier:sender: to push the correct viewController based on screen height.

The original question related to a segue that is setup to automatically fire by dragging between a UITableViewCell and a UIViewController in Interface Builder. Using this method you can only access one UIViewController via the segues one-to-one relationship.

You can get round this (and do what I originally asked) by wiring the segue directly from the UIViewController that contains the UITableView (rather from the cell itself) and then using tableView:didSelectRowAtIndexPath: to get the selected cell and perform the required segue. Using this method you can setup as many segues as required, by giving each segue a unique identifier you can programatically control which gets called (and when) by using -performSegueWithIdentifier:sender:

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