所以假设我在 viewcontroller C 中,我想转换到 viewcontroller D(这里是 voteView)。所以这就是我所做的:
VoteViewController * voteView = [[VoteViewController alloc] init];
voteView.voteInfo = [array objectAtIndex:0];
NSArray * viewControllers = [self.navigationController viewControllers];
if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
NSLog(@"LIST VIEW");
} else if ([[viewControllers objectAtIndex:0] isKindOfClass:[SpotListingViewController class]]){
NSLog(@"SPOT LISTING");
}
[self.navigationController setViewControllers:[NSArray arrayWithObjects:[viewControllers objectAtIndex:0], [viewControllers objectAtIndex:1], voteView, nil]];
[voteView release];
运行上面的代码,它打印出 LIST VIEW,这意味着 RootViewController 是一个 ListViewController。现在理论上在 VoteViewController 当我执行以下操作时:
if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
NSLog(@"LIST VIEW");
它应该打印 LIST VIEW,但它没有。为什么是这样?我还检查了视图控制器的计数,它只有 2。为什么它不同?