在我的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;
}
然后在classA,我正在做
- (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
我认为使用setViewControllers
我现在迷路了,需要你们的一些建议。如果您对此问题有任何想法,请提供帮助。 感谢
答案 0 :(得分:0)
self.window.rootViewController = classA
我改变了答案。 self.navigationController.rootViewController错误