user1256477
user1256477

Reputation: 11201

how to move to popToViewController: from tabBarController

I have my app is a TabBarController, and I have to take different actions depending on which tab is pressed, so, I delegate TabBarContoller, and I got it.

Now in case a tab which contents a NavigationController is pressed, depending on a database value, the view that should be shown is the first one or the last one, so in Tabs.m:

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
 NSArray *viewArrays = [(UINavigationController*)viewController viewControllers];

switch (tabBarController.selectedIndex) {

    case 3:
    {
        NSString *query = @"SELECT * FROM login";
        sqlite3_stmt *statement = [[Database alloc] select:query];

        if(sqlite3_step(statement) == SQLITE_ROW) {
           [(UINavigationController*)viewController popToViewController:[viewArrays objectAtIndex:1] animated:YES];

        }
        sqlite3_finalize(statement);
        break;
    }
    default:
        break;
}

}

The problem is objectAtIndex:1 doesn't exist right now

Upvotes: 0

Views: 1071

Answers (1)

Neo
Neo

Reputation: 2807

You can popView only if you have done pushView atleast once. Print and see the objects inside self.navigationController.viewControllers using NSLog and if it contains some object then give your index appropriately(within the range), i am confused why you are doing (UINavigationController*)viewController, try this instead

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];

Upvotes: 1

Related Questions