UITabViewController 中的共享数据
Shared data in UITabViewController
我希望 TabBarController 的所有子视图都可以访问相同的信息。
我有一个导航控制器,可以让用户 select 一行。当它被 selected 时,它会将 NSMutableDictionary
推送到 TabBarController 中的第一个 ViewController。布局见截图。
这很好用,但我如何让其他视图访问同一条信息?
字典包含很多信息,我想将其分解到其他屏幕。
来自我的 UINavigationController
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITabBarController *tbc = (UITabBarController*)segue.destinationViewController;
CallDetailViewController *dv = [tbc childViewControllers][0];
dv.thisDictionary = Some dictionary;
}
在我的选项卡中的第一个 UIViewController
@interface CallDetailViewController : UIViewController
@property (weak, nonatomic) NSMutableDictionary* thisDictionary;
@end
每个 UIViewController 上都需要 NSMutableDictionary
吗?或者我可以调用一些主词典文件吗?
可能值得注意,我目前没有使用 UITabViewController 文件。
你可以把你的字典 属性 放在你的 TabBarController 中,这样所有的 childViewControllers 都可以访问它,最简单的方法是子类化 UITabBarController,并从每个 childViewControllers 访问它的属性:
[(MyTabBarController *)self.tabBarController thisDictionary];
它也有助于从所有 childViewControllers 操作这个字典
我希望 TabBarController 的所有子视图都可以访问相同的信息。
我有一个导航控制器,可以让用户 select 一行。当它被 selected 时,它会将 NSMutableDictionary
推送到 TabBarController 中的第一个 ViewController。布局见截图。
这很好用,但我如何让其他视图访问同一条信息?
字典包含很多信息,我想将其分解到其他屏幕。
来自我的 UINavigationController
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITabBarController *tbc = (UITabBarController*)segue.destinationViewController;
CallDetailViewController *dv = [tbc childViewControllers][0];
dv.thisDictionary = Some dictionary;
}
在我的选项卡中的第一个 UIViewController
@interface CallDetailViewController : UIViewController
@property (weak, nonatomic) NSMutableDictionary* thisDictionary;
@end
每个 UIViewController 上都需要 NSMutableDictionary
吗?或者我可以调用一些主词典文件吗?
可能值得注意,我目前没有使用 UITabViewController 文件。
你可以把你的字典 属性 放在你的 TabBarController 中,这样所有的 childViewControllers 都可以访问它,最简单的方法是子类化 UITabBarController,并从每个 childViewControllers 访问它的属性:
[(MyTabBarController *)self.tabBarController thisDictionary];
它也有助于从所有 childViewControllers 操作这个字典