0

在我的 appDelegate 中,我将 ClassA 设置为导航控制器的根视图,如下所示

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
  self.window       =   [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  ClassA    *classA =   [[ClassA alloc] initWithNibName:@"ClassA" bundle:nil];

  self.navigationController  =   [[UINavigationController alloc] classA];
  [self.window makeKeyAndVisible];
  return YES;
}

然后在A类,我在做

- (void)myMethod {
  NSMutableArray *navigationArray1 = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];    

  NSLog(@"before using setViewControlles---->navigationarray.viewControllers is %d",[navigationArray1 count]);

  ClassB     *classB     =   [[ClassB alloc] initWithNibName:@"ClassB" bundle:nil];
  [self.navigationController setViewControllers:[NSArray arrayWithObject:classB] animated:YES]; 

  NSMutableArray *navigationarray2 = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
  NSLog(@"after using setViewControllers---->navigationController.viewControllers is %d",[navigationarray2 count]);

}

在调试模式下,我得到

before using setViewControlles---->navigationarray.viewControllers is 1
after  using setViewControlles---->navigationarray.viewControllers is 0

我认为使用后的结果应该是 1setViewControllers

我现在迷路了,需要你们的一些建议。如果您对此问题有任何想法,请提供帮助。谢谢

4

1 回答 1

0
self.window.rootViewController = classA

我改变了答案。self.navigationController.rootViewController 错误

于 2012-09-12T23:20:40.140 回答