gpt4 book ai didi

iphone - 管理 NSNotification 以及 UITabBarController 交互

转载 作者:行者123 更新时间:2023-12-03 21:22:17 27 4
gpt4 key购买 nike

我有 1 个主 UIViewController,其中包含一个 UITabBarController。标签栏 Controller 有 4 个 UIViewController(每个都由 UINavigationController 管理)。简而言之,它看起来像这样:

MainViewController   |   |--- FirstUIViewController   |   |--- SecondUIViewController   |   |--- ThirdUIViewController   |   |--- FourthUIViewController

默认加载 FirstUIViewController。

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

1)在选项卡栏 Controller 中选择 FourthUIViewController,以直观地显示已进入不同的选项卡。

2) FourthUIViewController 中的后续操作,其中选择特定的 UITableViewCell。所选单元格由事件中传递的数据确定。

为了做到这一点,我在 MainViewController 中创建了一个 NSNotification 观察者。它监听来自 SecondUIViewController 的事件并通过 userInfo 从中获取数据。

我还知道,从 MainViewController 中,我可以轻松地在 UITabBarController 上设置 selectedIndex,以便显示正确的选项卡。 (#1 已完成)。

然而,实现#2 让我感到困惑。我不知道如何(正确地、正确地)设置选项卡栏的 selectedIndex ,然后让 FourthUiViewController 作用于选定的单元格。我的假设是,在此事件发生之前,FourthUIViewController 可能尚未加载,因此我无法设置任何参数或调用任何观察者。

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

TIA。

最佳答案

View Controller 将始终在启动时加载,除非您对 NIB 文件做了一些非常奇怪的事情。

Controller 的 View 可能尚未加载,但您可以通过调用[fourthController view](或者,如果合适的话,[self view]),然后再操作该 View 的表格。

关于iphone - 管理 NSNotification 以及 UITabBarController 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3550401/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com