I have added a UITabBarController programatically (Search,Login) and I want to set second tabbaritem(Login) and its view to be selected when Login credentials are not correct.But I m unable to do it so ..Could not understand where I m going wrong ..?
Search *first = [[Search alloc] initWithNibName:@"Search" bundle:nil];
first.title=@"Search";
Login *second=[[Login alloc]initWithNibName:@"Login" bundle:nil];
second.title=@"Login";
NSArray *viewArray= [NSArray arrayWithObjects:first,second, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[tabBarController setSelectedIndex:2];
[self presentModalViewController:tabBarController animated:NO];
But here my SearchViewController is selected and displayed as default…Where i m going wrong..?
Error is in this line:
Counting starts not from 1 but from 0, so in your case you have to change it to: