使用iOS和Storyboard对UIViewControllers进行编程循环 [英] Programming UIViewControllers cycles with ios and storyboard

查看:39
本文介绍了使用iOS和Storyboard对UIViewControllers进行编程循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用IOS 5和情节提要进行ios开发,并且想知道如何解决以下问题:

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

我有一个树形层次结构,其类别是产品是树的节点,产品是叶子.我创建了一个TileViewController视图,以显示特定级别的所有节点.当用户在TileView中选择一个节点时,根据其类型(叶子还是非叶子),我要么将一个新的TileViewController推入应用程序NavigationController中,要么显示一个DetailViewController.

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.

我目前要做的是以编程方式进行所有操作(我的意思是跟踪用户在TileViewController中单击的内容,然后确定在NavigationController中下一步要推送的内容).我在情节提要板上有一个手柄,并根据需要使用以下代码创建下一个TileViewController.

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];

我不知道是如何使用情节提要而不是TileViewController中的硬编码逻辑来实现的.这是可能吗?我考虑过使用单个TileViewController并仅根据用户选择重新加载显示的图块,但随后我失去了导航功能.有什么想法可以实现这一目标吗?

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?

谢谢.

推荐答案

您可以从启动导航的任何UI组件定义故事,回到情节提要中的同一场景-因此,如果它是来自按钮的,则ctrl-从按钮向下拖动到代表图块视图控制器的黄色球形.

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.

将其定义为强制搜索,然后在prepareForSegue中传递相关细节.这将创建潜在的无限导航堆栈,而无需在情节提要中重复自己.

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.

这篇关于使用iOS和Storyboard对UIViewControllers进行编程循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆