如何使用故事板与选项卡栏控制器作为初始控制器共享UIManagedDocument? [英] How to share a UIManagedDocument using Storyboards with a Tab Bar Controller as initial controller?

查看:173
本文介绍了如何使用故事板与选项卡栏控制器作为初始控制器共享UIManagedDocument?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式会使用位置资料,并将其显示为表格和地图。

My application uses locations data and presents it both as a table and in a map.

它以Tab键控制器开始,每个视图都是导航控制器(一个用于表视图,一个用于映射等)。

It starts with a Tab Bar Controller, each of it's views is a Navigation Controller (one for the table view, one for the map, etc...).

我想共享一个UIManagedObject,以便使用相同的受管对象上下文如果用户在表视图中更新,数据也会更新为地图,因此不需要更新两次。

I want to share a UIManagedObject in order to use the same Managed Object Context so if the user updates at the table view, the data also gets updated for the map, so there is no need to update twice.

最初我想到了子类化Tab键控制器并添加一个UIManagedDocument作为属性,并将其传递给每个控制器,准备segue方法。但我读到UITabBarController不是要被子类化。

Originally i thought of subclassing the Tab Bar Controller and adding a UIManagedDocument as a property, and just passing it to each controller on the prepare for segue method. But i read that UITabBarController is not meant to be subclassed.

另一种方法可以创建一个View Controller,添加Managed Document作为属性,一个Tab Bar。但我认为我的故事情节将不清楚或不一致通过图形显示一些关系和其他只是在代码中。

Another approach could be creating a View Controller, adding the Managed Document as property, and a Tab Bar to it. But i think that my storyboard would be unclear or inconsistent by showing some relationships graphically and others just in code.

哪一个是适当的?或者有更好的方法吗?

Which one is the appropriate? Or is there a better way to do it?

提前感谢和最好的问候。

Thanks in advance and best regards.

推荐答案

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showGuide"]) 
    {
        UITabBarController *tabBarController = (UITabBarController *)[segue destinationViewController];
        for (id vc in tabBarController.viewControllers) {      
            [vc setValue:_document forKey:@"document"];            
    }
}

这篇关于如何使用故事板与选项卡栏控制器作为初始控制器共享UIManagedDocument?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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