【问题标题】:pushViewController Not Displaying UIView/Nib with tabbar and nav barpushViewController 不显示带有标签栏和导航栏的 UIView/Nib
【发布时间】:2010-05-03 06:14:38
【问题描述】:

我对 Objective c 比较陌生,但不会编程,而且我的 iPhone 应用程序卡住了。

我创建了一个带有导航栏和标签栏控制器的基于导航的应用程序。我将标签栏设置为根控制器。我能够在每个选项卡之间切换,而对各种 UIView 和 UITableView 没有任何问题。

我的问题是,在我从 TabBarController 调用的 UITableViews 中,didSelectRowAtIndexPath 函数假设显示一个新的 UIView。下面的代码没有给出任何错误并且运行良好,但没有显示新的 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];

现在,当我执行以下操作时,它工作正常,但它摆脱了我假设的导航和选项卡,因为它是模态调用而不是推送视图控制器。

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

任何想法为什么我不能让视图控制器正确推送?在我的应用程序委托文件中,我声明了一个名为 appNavBar 的 AppNavBarController 对象(继承自 UINavigationController)。

任何帮助将不胜感激!

【问题讨论】:

    标签: iphone uinavigationcontroller


    【解决方案1】:

    如果您想将视图显示为带有导航控制器的模态视图,您可以按如下方式进行:

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

    另外,据我所知,您的应用程序委托中有您的导航控制器。所以我猜你正在为所有选项卡视图使用全局导航控制器,理想情况下不应该是这种情况。您的导航控制器应该在您的选项卡控制器中,最好您需要在不同的选项卡中有不同的导航控制器。

    【讨论】:

    • 感谢您的回复。您的代码看起来会完成与我提供的代码相同的功能,它会在没有全局导航栏和全局标签栏的情况下显示新的 UIView。
    【解决方案2】:

    我实际上找到了答案。我不确定我是否理解为什么上面的代码不起作用,但以下代码完成了我想要的: [self.navigationController pushViewController:newControllerName Animation:YES];

    【讨论】:

      猜你喜欢
      • 2014-12-30
      • 1970-01-01
      • 2012-08-03
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多