views:

375

answers:

2

I'm relatively new to objective c but not programming and am stuck with my iphone app.

I created a nav based app with both a navbar and a tab bar controller. I set the tab bar as the root controller. I'm able to switch between each tab without any issues to various UIViews and UITableViews.

My issue is that in one of my UITableViews that I call from the TabBarController, didSelectRowAtIndexPath function is suppose to display a new UIView. The below code does not give any errors and runs fine but does not show the new Nib.

if(newViewController == nil) {  
NSLog(@"yes nil");  
BookViewController *aNewViewController = [[BookViewController alloc] initWithNibName:@"BookOptionView" bundle:nil];   
self.newViewController = aNewViewController;     
[aNewViewController release];    
} 
BookAppDelegate *delegate = (BookAppDelegate *)[[UIApplication sharedApplication] delegate]; 
[delegate.appNavBar pushViewController:newViewController animated:YES];

Now when I do the below, it works fine but it gets rid of the nav and tab which I'm assuming because its a modal call instead of pushing the view controller.

BookViewController *screen = [[BookViewController alloc] initWithNibName:@"BookOptionView" bundle:[NSBundle mainBundle]];  
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;  
[self presentModalViewController:screen animated:YES];  
[screen release];  

Any ideas why I can't get the View Controller to push correctly? In my application delegate file, I declared an AppNavBarController object (inherit from UINavigationController) called appNavBar.

Any help would be appreciated!

A: 

If you want to present your view as a modal view with nav controller, you can do it as below:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
[self presentModalViewController:navigationController animated:YES]; 

Also, from what I see, you have your navcontroller in your appdelegate. So I guess you are using a global navcontroller for all your tab views, which ideally shouldn't be the case. Your navcontroller should be within your tab controller and preferably you need to have different nav controllers in different tabs.

Hetal Vora
Thanks for the response. Your code looks like it would accomplish the same thing the code I provided where it would display a new UIView without the global navbar and global tabbar I have.
james
A: 

I actually found my answer. I'm not sure I understand why my code above doesn't work but the following accomplishes what I want: [self.navigationController pushViewController:newControllerName animated:YES];

james