Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-05-2011, 08:38 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 50
Maxner is on a distinguished road
Default Switching Views in Navigation Based app with Navigation Bar Button

I am workin on a Navigation Based app, with a table view and a navigation bar on the first view. On the Navigation Bar ive got a + Button that should open up another view. Ive tried this code:
SecondView *second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentModalVewController:second animated:YES];

It works inside a view based app but the ground structure of a navigation based app is completely different, so that i cant do the steps that work with the view based app. Because normally you dont do anything on the mainWndow.xib but you do on the viewcontroller.xib. in this case although ive got the navigation bar with the button on the mainwindow.xib and thats what messes everthing up. Ive tried to add an object and connect it to a viewcontrollersubclass to recieve the IBActions, but then tha app always crashes when i press the button! Can anyone help me with this
Maxner is offline   Reply With Quote
Old 06-05-2011, 09:02 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
[self.navigationController pushViewController:secondViewController];
where navigationController is a pointer to your UINavigationController
__________________
dany_dev is offline   Reply With Quote
Old 06-05-2011, 09:50 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 50
Maxner is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
where navigationController is a pointer to your UINavigationController
I had no success!
So basically i added a .h and a .m file called first. in first i made the actions and in the inteface builder I added an object and set it to First so that i had the possibility to connect the action to the bar button in MainWindow.xib. But if i click the button nothing happens, if i use your code its the same. Can you please try to build the same ting with xcode and then tell me how it works?
Maxner is offline   Reply With Quote
Old 06-05-2011, 10:12 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

I suppose that your problem is that your reference to navigationController is not the right reference.....you should put it on appDelegate, so that you can have its reference esaily.

to confirm that this is the problem:
Code:
[self.navigationController pushViewController:secondViewController]; 
if(!self.navigationController)
    NSLog(@"navigationController is NIL!!!!");
__________________
dany_dev is offline   Reply With Quote
Old 06-05-2011, 11:17 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 50
Maxner is on a distinguished road
Default

thank you dany, it works perfectly! So the coplete code for the ibaction is:
Code:
- (IBAction)switchto2:(id)sender {
    Second *second = [[Second alloc] initWithNibName:nil bundle:nil];
    [self.NavController pushViewController:second animated:YES]; 
    if(!self.NavController)
        NSLog(@"navigationController is NIL!!!!");

}
Maxner is offline   Reply With Quote
Old 06-05-2011, 11:41 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

and remember to release, to avoid leak.

Code:
- (IBAction)switchto2:(id)sender {
    Second *second = [[Second alloc] initWithNibName:nil bundle:nil];
    [self.NavController pushViewController:second animated:YES]; 
    [second release];
}
__________________
dany_dev is offline   Reply With Quote
Old 06-05-2011, 12:47 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 50
Maxner is on a distinguished road
Default

right
is there a way to change the transtion in this case? because UIModalTransitionStyle doesnt work with the navigation controller.
Maxner is offline   Reply With Quote
Reply

Bookmarks

Tags
navigation, navigation based, switch, views, xcode 4

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 319
6 members and 313 guests
chemistry, Dnnake, iOS.Lover, jenniead38, pbart, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0