how to move to popToViewController: from tabBarController

杀马特。学长 韩版系。学妹 提交于 2019-12-25 05:18:52

问题


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


回答1:


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];


来源:https://stackoverflow.com/questions/12527581/how-to-move-to-poptoviewcontroller-from-tabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!