didSelectRowAtIndexPath and segues

孤人 提交于 2019-12-01 22:36:44

问题


I am working with Storyboard. I am in doubt regarding the use of segues when pushing a new UItableViewController onto the navigation stack. How to do it right? No segue when the push results from a tap in a cell and just use didSelectRowAtIndexPath? Please share your opinion.


回答1:


You do not mention it at all, but judging by your mention of a segue you are using storyboarding.

When using storyboarding there is a new way to show a new view controller. By connecting a UITableViewCell using a seque to a new view controller in Interface Builder. When you do that, there's no need to use didSelectRowAtIndexPath: because the new view controller will be displayed automatically. You can however prepare your segue, and set parameters on the new view controller for example:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // assumes only one type, more extensive checking before cast to 
    // make it safer is needed.
    MyViewController *viewController = (MyViewController *) segue.destinationViewController;

    viewController.detailObject = myModelObject;
}

For any tableview cell that is not connected using a segue you can provide your own behaviour using plain old tableView:didSelectRowAtIndexPath:.

There is no correct way, just use whatever seems easiest to you.



来源:https://stackoverflow.com/questions/9191619/didselectrowatindexpath-and-segues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!