views:

120

answers:

2

Hi everyone, my first question here so be gentle :)

I am trying to use a navigationController to switch views. I got the following down: I got a MainView controller which switches to different view controllers using this code:

UIButton *buttonPressed = (UIButton *)sender;

    switch (buttonPressed.tag) {
    case 1:
        viewController = catalogView;
        break;
    case 2: 
        viewController = locatorView;
        break;
    case 3:
        viewController = galleryView;
        break;
}
[[self navigationController] pushViewController:viewController animated:YES];

Now I try, to switch to another view in one of these views.

I figured: I have to import the main view and simply create a method here to switch views.

e.g.

- (IBAction)goToProductView {
    //UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Test" message:@"hier" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil] autorelease];
    //[alert show];
    viewController = galleryView;
    [[self navigationController] pushViewController:viewController animated:YES];
}

and I call this function from within a viewcontroller like so:

myViewController *mainView = [[myViewController alloc] init];
[[self navigationController] popViewControllerAnimated:NO];
[mainView goToProductView];

The function of mainView gets called here (the alert shows if I unquote it) but the view does not change.

Anyone here can tell me why, or has a better solution?

Thanks in advance

(ps. if I missed any information please feel free to ask and I will supply them asap)

A: 

Your flow of calling views/view controllers is not correct. If you can explain correct scenario of what you want, i'll tell the solution to you. Or post your code to understand better.

Satyam svv
A: 

I have found the error of my ways.

I was nesting Views like this:

mainView - SecondView ThirdView

and asking mainView to go from SecondView to the ThirdView.

instead of this:

MainView - SecondView - ThirdView

and now simply ask the secondView to go to the thirdView.

For anyone else reaching here with the same problem I found http://www.edumobile.org/iphone/iphone-programming-tutorials/navigationcontroller-application-in-iphone/ to be extremely usefull.

Tjirp