0

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 LISTING");
    }

    [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?

DShah
  • 9,768
  • 11
  • 71
  • 127
xonegirlz
  • 8,889
  • 19
  • 69
  • 127

1 Answers1

1

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?

Akshay
  • 5,747
  • 3
  • 23
  • 35