Programming UIViewControllers cycles with ios and storyboard

╄→尐↘猪︶ㄣ 提交于 2019-12-23 02:29:15

问题


I am just starting ios development with IOS 5 and storyboards and would like to know how I can solve the following problem:

I have a tree hierarchy with categories an products being nodes of the tree and products are leaves. I created a TileViewController view to display all nodes at a specific level. When the user selects a node in the TileView, depending on its type (leaf or not-leaf) I either push a new TileViewController into the application NavigationController or I show a DetailViewController.

What I do currently is to do everything programmatically(By that I mean tracking what the user clicked on in the TileViewController and decide what to push next in the NavigationController). I get a handle on the storyboard and use the below code to create the next TileViewController if needed.

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        TileViewController *controller =  [storyBoard instantiateViewControllerWithIdentifier:@"TileViewController"];
        controller.model = self.model;   
        [self.navigationController pushViewController:controller animated:YES];

What I can't figure out is how to make this using a storyboard instead of hardcoding logic in the TileViewController. Is this at all possible? I thought about using a single TileViewController and just reloading the tiles displayed based on the user selection but then I lose the navigation piece. Any ideas how I could achieve this?

Thank you.


回答1:


You can define a segue from whatever UI component kicks off the navigation, back to the same scene in the storyboard - so if it was from a button, ctrl-drag from the button down to the yellow sphere representing the tile view controller.

Define this as a push segue, then pass the relevant detail in prepareForSegue. This will create a potentially infinite navigation stack without having to repeat yourself in the storyboard.



来源:https://stackoverflow.com/questions/10767573/programming-uiviewcontrollers-cycles-with-ios-and-storyboard

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