我有1个主UIViewController,其中包含一个UITabBarController.标签栏控制器具有4个UIViewControllers(每个UIViewControllers由UINavigationControllers管理).简而言之,它看起来像这样:
I have 1 main UIViewController that contains a UITabBarController. The tab bar controller has 4 UIViewControllers (each managed by UINavigationControllers). Succinctly, it looks like this:
MainViewController | |--- FirstUIViewController | |--- SecondUIViewController | |--- ThirdUIViewController | |--- FourthUIViewController默认情况下,FirstUIViewController已加载.
The FirstUIViewController is loaded by default.
在SecondUIViewController中,可能发生一个事件.此事件具有与之一起传递的特定数据.当此事件发生时,我希望发生两件事:
In the SecondUIViewController, there is an event that can occur. This event has specific data that is passed along with it. When this event occurs I want 2 things to happen:
1)已在选项卡栏控制器中选择"FourthUIUIViewController"以直观地显示另一个选项卡.
1) FourthUIViewController to be selected in the tab bar controller to visually show a different tab has been entered.
2)在ThirdUIViewController中的后续操作,其中选择了特定的UITableViewCell.所选单元格由事件中传递的数据确定.
2) A subsequent action in FourthUIViewController where a specific UITableViewCell is selected. The selected cell is determined by the data that is passed along in the event.
为此,我在MainViewController中创建了一个NSNotification观察器.它从SecondUIViewController监听事件,并通过userInfo从事件中获取数据.
In order to do this, I've created an NSNotification observer in the MainViewController. It listens for the event from the SecondUIViewController and gets data from it via userInfo.
我也知道从MainViewController可以轻松地在UITabBarController上设置selectedIndex,以便显示正确的选项卡. (排名第一).
I also know that from MainViewController I can easily set the selectedIndex on the UITabBarController in order to have the correct tab shown. (#1 accomplished).
但是,完成#2令我感到困惑.我不知道如何(正确地,正确地)设置选项卡栏的selectedIndex,然后让FourthUiViewController对选定的单元格起作用.我的假设是,在此事件发生之前可能尚未加载FourthUIViewController,因此我无法设置任何参数或调用任何观察者.
However, accomplishing #2 baffles me. I don't know how to (properly, correctly) set the selectedIndex of the tab bar and then have the FourthUiViewController act upon a selected cell. My assumption is that FourthUIViewController may not have been loaded before this event occurs so I couldn't set any parameters or call any observers.
也许更广泛的问题是通过选项卡选择加载UIViewController时如何传递数据(与推送一个非常简单的新UIViewController相比).
Perhaps the broader question is how data can be passed when loading a UIViewController through tab selection (compared to pushing a new UIViewController which is very straightforward).
TIA.
推荐答案视图 controller 将始终在启动时加载,除非您对NIB文件做了非常奇怪的事情.
The view controller will always be loaded at startup, unless you've done something very weird with your NIB file.
可能未加载控制器的视图,但是您可以在操作该视图的视图之前调用[fourthController view](或者,如果合适,[self view])来强制执行该操作桌子.
It's possible that the controller's view won't have been loaded, but you can force that to happen by calling [fourthController view] (or, if appropriate, [self view]) before you manipulate that view's table.
更多推荐
管理NSNotification以及UITabBarController交互
发布评论