0

I want to disable and enable later an UITabbarItem from the AppDelegate.m. (To be specific, on didFinishLaunchingWithOptions should it be disabled and after a NSURLConnection it should be enabled. I already tried creating a external method in the First View Controller and calling it from the Delegate, but it do not work. Here is my attempt:

FirstViewController.m:

-(void)enableDataTab {

[[[[self.tabBarController tabBar] items] objectAtIndex:1] setEnabled:YES];

}

AppDelegate.m:

    homeVC = [[FirstViewController alloc] init];
    [homeVC disableDataTab];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
IR Works
  • 49
  • 6

1 Answers1

1

Like this (in the view controller):

self.tabBarItem.enabled = NO;

Or like this (in the app delegate):

myFirstViewController.tabBarItem.enabled = NO;

The tab bar item representing a view controller is a property of that view controller.

Also, don't say

homeVC = [[FirstViewController alloc] init];

That makes a whole new FirstViewController. You don't want a new FirstViewController; you want the one that's already there as a child of the tab bar controller.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • You will need to obtain a reference to the actual view controller. I could give a better answer if you showed more of what you're doing in the app delegate and more about how the app itself is laid out. Is the root view controller a tab bar controller, and if so, are you creating it in code or in a storyboard? You need to reveal that kind of thing if you want more specific instructions. – matt Jan 04 '14 at 19:25
  • Okay, as I sad the AppDelegate starts a NSURlConnection and downloads some data at the application launch point. The UIViewControllers are set up in a storyboard. Maybe this is important: the rootViewVC is a TabBarController and the item I want to trigger belongs to a UITableViewController, which is embedded in a NavigationController. I'm sorry for making this so complicated. For now I have found a workaround: external BOOL and a NSTimer in the FirstViewController. – IR Works Jan 04 '14 at 19:34