2014-09-13 53 views
0

嗨,我刚开始开发我的第一个iOS应用程序,并完全坚持传递额外的选项到视图控制器。在UITabBarController中的活动视图

我的应用程序的入口控制器是UITabBarController。我在viewDidLoad方法,它看起来像

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self setSelectedIndex:1]; 
} 

但我不知道如何检索视图控制器对象传递更多选项它开始加载之前设置相应的选项卡。我应该在我的UITabBarController中执行哪种方法?

+0

additonal options mean other tab吧? – NullData 2014-09-13 14:05:25

+0

我想从我的'TabBarController'传递'managedObjectContext'到'TableViewController'。 – sneas 2014-09-13 15:57:51

回答

1

UITabBarController有一个属性名为selectedViewController

@property(nonatomic, assign) UIViewController *selectedViewController 

这是你在找什么?

但如果你想

通附加选项它开始加载

你需要与标签0,1做在的viewController的init方法

+0

感谢您的回复。正如我在上面评论中所说的,我想将'managedObjectContext'从'TabBarController'传递给'TableViewController',但是当我检查'selectedViewController'属性时,我看到'UINavigationController'的实例,是否有可能获得所选' TableViewController'? – sneas 2014-09-13 16:03:46

+0

@InSearch'navigationController.rootViewController'应该是'TableViewController' – dopcn 2014-09-13 16:26:52

+0

我终于在'selectedViewController'的'viewControllers'属性中找到了我的表视图控制器。 – sneas 2014-09-13 17:17:42

1

设置你的标签栏前,2,3分别使用此代码

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 
{ 


    switch (item.tag) { 
     case 0: 
     { 
      [self removeAllViews]; 


      break; 
     } 
     case 1: 
     { 
      [self removeAllViews]; 
      CategoriesVC *cvc=[[CategoriesVC alloc ]initWithNibName:@"CategoriesVC" bundle:nil]; 
      [self.view addSubview:cvc.view]; 
      if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) 
      { 

       if ([[UIScreen mainScreen] bounds].size.height == 568){ 
        CGRect frame = cvc.view.frame; 
        frame.size.height = [APPDELEGATE childViewHeight]; 
        cvc.view.frame = frame; 
       } 

      } 

      break; 

     } 
     case 2: 
     { 
      [self removeAllViews]; 
      FavoriteVC *fvc=[[FavoriteVC alloc ]initWithNibName:@"FavoriteVC" bundle:nil]; 
      [self.view addSubview:fvc.view]; 
      if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) 
      { 

       if ([[UIScreen mainScreen] bounds].size.height == 568){ 
        fvc.view.frame=CGRectMake(0,0,320,499); 
       } 

      } 

      break; 

     } 
     case 3: 
     { 
      [self removeAllViews]; 
      ProfileVC *pvc=[[ProfileVC alloc ]initWithNibName:@"ProfileVC" bundle:nil]; 

      [self.view addSubview:pvc.view]; 
      if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) 
      { 

       if ([[UIScreen mainScreen] bounds].size.height == 568){ 
        pvc.view.frame=CGRectMake(0,0,320,499); 
       } 

      } 

      break; 

     } 

    }} 
+0

感谢您的回复。我是Objective-C编程的新手,并没有真正知道这段代码如何帮助我获取实际的视图控制器? – sneas 2014-09-13 18:12:05