开发者

iPhone SDK: switching views navigationcontroller

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];
[[sel开发者_JAVA百科f 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)


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜