views:

180

answers:

2

Hi,

I don't know if my question will be clear or not, but i'm starting basic stuff with iphone programming, and i'm trying to understand how to go from a screen to another. lets say i have a screen with a "next page" button and another page with a "return" button. I have a general idea of how to do this, but I don't know how to put it together. I think I need an IBAction method for each button, and in each method a navigation controller with pushViewController. So far, i've tried the following code, but even if it compiles properly and runs when i push the button, there is no change of screen...

-(IBAction) toNext(id)sender{
NSLog(@"before code");
NextViewController *nvc = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController pushViewController:nvc animated:YES];
[nvc release];
NSLog(@"after code");
} 

If someone had a nice tuto for me, it could be of some help... thx

+3  A: 

Your code won't work if your view controller (and it's not clear that you are even doing this from a view controller) doesn't have a navigationcontroller.

Secondly, you should pop to return, not push a second time.

There are different ways of moving between views. The simplest is to call addSubview: with a view, which can be seen in the app delegate code of any app created from a template.

The two others are the push/pop used with navigation controllers (typically from a view controller), and present modal, which has to be called with a view controller as well. The differences with these latter two are the animations used, and the assumption of how the views will be navigated away from.

Paul Lynch
thanks for your answer paul. Im actually doing this from my first viewcontroller.m file.but then, how would you do with a navigationController? I have some trouble understanding the way these things work...I'm more a java programmer, and i'm starting with Objective C...
Sephy
My suggestion is that you download Apple's UICatalog example and look through it. This isn't an obj issue, it is a very simple (and very good) language - it is just a matter of becoming familiar with the cocoa-touch idioms.
Paul Lynch
A: 

I guess you are trying to implement a navigation based application in iPhone [Navigation Application][1]

[1]: http://theappleblog.com/2009/04/15/iphone-dev-sessions-create-a-navigation-based-application/ just go though it may be this is what you are looking for

sandy
thanks for this tuto, but I know how to navigate from a tableView to the detail of a row. What i'm trying to do is going from my first view to my tableview... and i can't get it to work when i think it like the TableView...
Sephy