1

I'm attempting to add view controllers to my tabbarcontroller, and then make the first one the selected one using the following code:

[self setViewControllers:[NSArray arrayWithObjects:self.detailController,self.mapController,nil] animated:NO];
[self setSelectedIndex:0];

When this code is called, the correct view controllers/tabs are added, but none are selected. Is there a better way to do this?

Update: To add more context, the above code snippet is being called in the viewDidLoad method of a view controller that subclasses UITabBarController.

iUser
  • 1,075
  • 3
  • 20
  • 49
midas06
  • 1,991
  • 2
  • 22
  • 43

2 Answers2

2

I have had the same problem, and using the following code seemed to help. Essentially, it adds a delayed reaction to the change. Sorry for the four year delay in response :)

dispatch_async(dispatch_get_main_queue(), ^{
    [self setSelectedIndex:2];
});
Jack Solomon
  • 880
  • 1
  • 8
  • 19
0

UITabBarController is possible to select the tab via code?

looks like it answers you question based on the code you have provided; if not can you show the code in context?

Community
  • 1
  • 1
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
  • 2
    That other question says the same thing im currently doing. The trick is the controller isn't responding. – midas06 Aug 23 '10 at 01:57