开发者

UINavigationController issue with popToRootViewController

So lets say that I am in viewcontroller, C and I want to transition to viewcontroller D (which is voteView here). So here's what I did:

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 LI开发者_JAVA百科STING");
    }

    [self.navigationController setViewControllers:[NSArray arrayWithObjects:[viewControllers objectAtIndex:0], [viewControllers objectAtIndex:1], voteView, nil]];
    [voteView release];

Running the code above, it prints LIST VIEW, which means that the RootViewController is a ListViewController. Now theoritically at VoteViewController when I do as below:

 if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
            NSLog(@"LIST VIEW");

it should print LIST VIEW, however it doesn't. Why is this? I also checked the count of the view controller and it's only 2. Why is it different?


If your ask is to transition to View Controller D (or voteView), you should be doing-

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

Related to your question, when you call setViewControllers: and access object at index 1, have you ensured that the array has two objects? In which method of voteView did you put the NSLog?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜