如何移动到 popToViewController:从 tabBarController [英] how to move to popToViewController: from tabBarController
问题描述
我的应用程序是一个 TabBarController,我必须根据按下的选项卡采取不同的操作,因此,我委托 TabBarContoller,我明白了.
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.
现在,如果按下包含导航控制器内容的选项卡,根据数据库值,应显示的视图是第一个或最后一个,因此在 Tabs.m 中:
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;
}
}
问题是 objectAtIndex:1 现在不存在
The problem is objectAtIndex:1 doesn't exist right now
推荐答案
只有至少执行过一次 pushView 才能使用 popView.使用 NSLog 打印并查看 self.navigationController.viewControllers 内的对象,如果它包含某个对象,则适当地提供您的索引(在范围内),我很困惑您为什么做 (UINavigationController*)viewController,试试这个
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];
这篇关于如何移动到 popToViewController:从 tabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!