0

所以假设我在 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。为什么它不同?

4

1 回答 1

1

如果您的要求是转换到 View Controller D(或voteView),您应该这样做-

[self.navigationController pushViewController:voteView animated:YES];

与您的问题相关,当您调用setViewControllers:和访问索引 1 处的对象时,您是否确保该数组有两个对象?你用什么方法voteView放的NSLog

于 2011-10-09T06:12:04.633 回答