开发者

pushViewController Not Displaying UIView/Nib with tabbar and nav bar

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 = UI开发者_如何学运维ModalTransitionStyleCoverVertical;  
[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!


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.


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];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜