我在我的app委托中设置了UINavigationController,并用它来推送我的登录页面。一旦loggeI-in,被调用的视图将显示UITabBarController,并为每个选项卡分别提供UINavigationController。我的问题是,当我通过我的标签栏中的导航控制器推送视图时,它什么都不做。它根本不会推动观点。我不知道接下来要做什么使pushViewController工作。很感谢任何形式的帮助。感谢。
这是我的代码:
登录时将从rootView类
调用此函数- (void) login
{
UIViewController *_mainPageViewController = [[MainPageViewController alloc] initWithNibName:@"MainPageViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:_mainPageViewController animated:YES];
}
MainPageViewController.class--
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self setUpTabBar];
}
return self;
}
-(void)setUpTabBar {
MeViewController *_meViewController = [[MeViewController alloc]init];
_meViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"me"
image:[UIImage imageNamed:@"img1.png"] tag:1];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:_meViewController];
TodoViewController *_todoViewController = [[TodoViewController alloc]init];
_meViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"me"
image:[UIImage imageNamed:@"img2.png"] tag:1];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:_meViewController];
mainBarController.viewControllers = [[NSArray alloc] initWithObjects: firstNavController, secondNavController, nil];
mainBarController.delegate = self;
mainBarController.selectedIndex=0;
[firstNavController release];
[_meViewController release];
[secondNavController release];
[_exploreViewController release];
[[[UIApplication sharedApplication]keyWindow]addSubview:mainBarController.view];
}
MeViewController.class--它根本不会推送视图
- (IBAction)showMeInfo:(id)sender {
UIViewController *_meInfoViewController = [[MeInfoViewController alloc] initWithNibName:@"MeInfoViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:_meInfoViewController animated:YES];
}
答案 0 :(得分:0)
我不确定我是否100%理解,但这里是 -
我假设MainPageViewController
是UITabBarController
的子类。如果是这种情况,则不需要mainBarController
变量,因为此类中的选项卡栏控制器将为self
。你会打电话给
self.viewControllers = [NSArray arrayWithObjects: firstNavController, secondNavController, nil];
另外,因为您要将MainPageViewController
的实例推送到现有的UINavigationController
实例,所以您不需要在MainPageViewController
代码中添加任何子视图 - 例如代码行
[[[UIApplication sharedApplication]keyWindow]addSubview:mainBarController.view];
不是必需的,也不应该存在(UINavigationController
会自动控制哪些视图可见等,具体取决于从导航堆栈中推送/弹出的视图控制器。)