uitabbar的topviewcontroller [英] topviewcontroller for uitabbar

查看:77
本文介绍了uitabbar的topviewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用coredata创建了一个基于导航的项目,并用tabbarcontroller替换了navigationcontroller. 但是我发现很难重写它:

I have created a navigation based project with coredata and replaced the navigationcontroller with a tabbarcontroller. But im finding it hard to rewrite this:

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;

谢谢.

推荐答案

UITabBarController没有根视图控制器,因为它不管理视图控制器的堆栈,而是管理数组(按顺序排列视图控制器)到标签栏中占用的插槽).

UITabBarController doesn't have a root view controller because it doesn't manage a stack of view controllers, but rather the array (with view controllers ordered according to the slots occupied in the tab bar).

此代码段将为标签栏控制器中的第一个(最左侧)视图控制器设置托管对象上下文:

This snippet of code will set managed object context for the first (leftmost) view controller in tab bar controller:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)[tabBarController.viewControllers objectAtIndex:0];
controller.managedObjectContext = self.managedObjectContext;

这篇关于uitabbar的topviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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