Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 管理NSNotification和UITabBarController交互_Iphone_Objective C_Uiviewcontroller_Uitabbarcontroller_Nsnotifications - Fatal编程技术网

Iphone 管理NSNotification和UITabBarController交互

Iphone 管理NSNotification和UITabBarController交互,iphone,objective-c,uiviewcontroller,uitabbarcontroller,nsnotifications,Iphone,Objective C,Uiviewcontroller,Uitabbarcontroller,Nsnotifications,我有一个主UIViewController,其中包含一个UIAbbarController。选项卡栏控制器有4个UIViewController,每个由UINavigationController管理。简而言之,它看起来是这样的: MainViewController | |--- FirstUIViewController | |--- SecondUIViewController | |--- ThirdUIViewController | |

我有一个主UIViewController,其中包含一个UIAbbarController。选项卡栏控制器有4个UIViewController,每个由UINavigationController管理。简而言之,它看起来是这样的:

MainViewController | |--- FirstUIViewController | |--- SecondUIViewController | |--- ThirdUIViewController | |--- FourthUIViewController 默认情况下加载FirstUIViewController

在SecondUIViewController中,可能会发生一个事件。此事件具有随它一起传递的特定数据。发生此事件时,我希望发生两件事:

1要在选项卡栏控制器中选择的FourthUI控制器,以直观地显示已输入的不同选项卡

2在FourthUI控件中选择特定UITableViewCell的后续操作。所选单元格由事件中传递的数据确定

为此,我在MainViewController中创建了一个NSNotification observer。它从SecondUIViewController侦听事件,并通过userInfo从中获取数据

我还知道,通过MainViewController,我可以轻松地在UITabBarController上设置selectedIndex,以便显示正确的选项卡。1.完成

然而,完成这两项任务让我感到困惑。我不知道如何正确地设置选项卡栏的selectedIndex,然后让FourthUI控件对所选单元格进行操作。我的假设是,在该事件发生之前,FourthUIViewController可能尚未加载,因此我无法设置任何参数或调用任何观察者

也许更广泛的问题是,与推送非常简单的新UIViewController相比,通过选项卡选择加载UIViewController时如何传递数据


TIA。

如果需要,通知可以有多个收件人。为什么不让您的其他视图简单地侦听相同的通知,并根据UserInfo选择所需的表呢

我理解得对吗?

视图控制器将始终在启动时加载,除非您对NIB文件做了一些非常奇怪的操作


控制器的视图可能未加载,但您可以通过调用[fourthController view]或(如果合适)调用[self view]强制加载操作该视图的表之前。

我相信在抛出事件时,另一个视图控制器可能未初始化,因此无法侦听事件。这是假设视图控制器在第一次选择其选项卡之前一直处于初始化状态。在这种情况下,可以使用NSUserDefaults传递此信息。当用户数据第一次加载时,您可以从该空间将其写入NSUserDefaults和新视图inits。加载后,它可以侦听通知中的数据。