Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select tab from UITabBarController programmatically and load view

I am having an issue loading the view of selected tab item.

I am using the code below in the viewDidLoad of the UIViewController at item 1 of the UITabBar.

UITabBarController *tab = self.tabBarController;

if (tab){
   NSLog(@"I have a tab bar");
   [self.tabBarController setSelectedIndex:1];
   [self.tabBarController.view setNeedsDisplay];
   self.tabBarController.selectedIndex=1;
} else {
    NSLog(@"I don't have");
}

When I press Back To Tab Controller Button, it selects the tab but it doesn't open the required view. It shows the view of the tab at index 0.

enter image description here

like image 728
TechFanatic Avatar asked Jun 18 '26 02:06

TechFanatic


1 Answers

Write your code in viewDidAppear: method instead of view did load. it will work..

like image 108
Rajath Shetty K Avatar answered Jun 19 '26 15:06

Rajath Shetty K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!