1

我的应用程序委托中有我的 UINavigationController 设置,我用它来推送我的登录页面。登录后,正在调用的视图将显示 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];
}
4

1 回答 1

0

我不确定我是否 100% 理解,但这里是 -

我认为这MainPageViewControllerUITabBarController. 如果是这种情况,则mainBarController不需要该变量,因为此类中的选项卡栏控制器将是self. 你会打电话给

self.viewControllers = [NSArray arrayWithObjects: firstNavController, secondNavController, nil];

此外,因为您将实例推MainPageViewController送到现有UINavigationController实例上,所以您不需要在MainPageViewController代码中添加任何子视图 - 例如代码行

[[[UIApplication sharedApplication]keyWindow]addSubview:mainBarController.view];

不是必需的,也不应该存在(UINavigationController自动控制哪些视图可见等,具体取决于从导航堆栈中推送/弹出哪些视图控制器。)

于 2012-09-25T14:08:23.940 回答