呈现模态视图控制器隐藏导航栏

我有一个导航栏的应用程序导航,但有一些实例,而不是将视图控制器推到堆栈上,我需要以模态方式呈现视图控制器。 问题是,当我closures模式视图控制器时,除了导航栏被隐藏和(父视图)已被resize,这是根据文档预期的行为,一切都按预期运行。 所以我想我可以简单地调用一个内置的方法来取消隐藏导航栏。 我已经尝试过了

[self.navigationController setNavigationBarHidden:NO]; 

以及没有成功的animation版本。

文档在方法中谈到这个

 presentModalViewController: animated: 

在它所说的讨论部分,

在iPhone和iPod touch设备上,modalViewController的视图始终呈现为全屏“and”将modalViewController属性设置为指定的视图控制器。 调整其视图并将其附加到视图层次结构中。“然而,文档并没有告诉我如何在驳回模式视图之后撤销这个过程。

有没有其他人经历过这个,find了解决办法?

编辑:我有这个相同的问题,所以不要问我自己的问题,我赞助这一个奖金。 这是我的具体情况:

在我的情况下,我通过导航控制器在模态视图控制器中显示图像select器:

 -(void) chooseImage { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { imagepicker = [[UIImagePickerController alloc] init]; imagepicker.allowsEditing = NO; imagepicker.delegate = self; imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagepicker.navigationBar.opaque = true; imagepicker.wantsFullScreenLayout = NO; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (self.view.window != nil) { popoverController = [[UIPopoverController alloc] initWithContentViewController:imagepicker]; [popoverController presentPopoverFromBarButtonItem:reset permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; } else {} } else { [self.navigationController presentModalViewController:imagepicker animated:YES]; } } } -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [self.popoverController dismissPopoverAnimated:true]; } else { [self.navigationController dismissModalViewControllerAnimated:YES]; } //Save the image } -(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [self.popoverController dismissPopoverAnimated:true]; } else { [self.navigationController dismissModalViewControllerAnimated:YES]; } } 

确保你提交并从UINavigationController退出modalViewController,如下所示:

 // show [self.navigationController presentModalViewController:vc animated:YES]; // dismiss [self.navigationController dismissModalViewControllerAnimated:YES]; 

如果您的视图控制器实际上在UINavigationController的堆栈上,那么这是处理模态视图控制器的呈现和解除的正确方法。 如果你的UINavigationBar仍然隐藏,还有其他的东西正在发生,我们需要看你的代码来确定发生了什么。

编辑

我把你的代码复制到了我的应用程序中,UIImagePickerController成功地呈现和解散,我的UINavigationController的UINavigationBar仍然存在。 我真的相信这个问题在你的架构的其他地方。 如果你上传一个带示例项目的邮件,我会看看。

只要尝试下面的代码,它将工作

 SettingsViewController *settings = [[SettingsViewController alloc] init]; UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:settings]; [self presentModalViewController:navcont animated:YES]; [settings release]; [navcont release]; 

一个需要呈现导航控制器以在所呈现的控制器上具有导航栏

我认为在错误的VC上呈现视图控制器时,我已经看到了这种行为。 您是否在导航控制器或单个VC上调用presentModalViewController

尝试从navigationController调用它,如果你还没有。

 [self.navigationController presentModalViewController:myVC animated:YES]; 

如果您将控制器作为模型呈现,则视图控制器将显示为总视图。

如果要通过模型视图访问导航控制器属性,则需要创build另一个导航控制器参考,并按前面的说明继续。

这可能对你有用。

看一下这个。 这是UIViewController类参考下的Apple文档:

它清楚地提到模态视图总是以全屏模式呈现,所以导航栏显然是隐藏的。 因此,将模块视图中的单独导航栏导航回来。

 presentModalViewController:animated: Presents a modal view managed by the given view controller to the user. - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated Parameters modalViewController The view controller that manages the modal view. animated If YES, animates the view as it's presented; otherwise, does not. Discussion On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property. Sets the modalViewController property to the specified view controller. Resizes its view and attaches it to the view hierarchy. The view is animated according to the transition style specified in the modalTransitionStyle property of the controller in the modalViewController parameter. Availability Available in iOS 2.0 and later. 

希望这有助于你理解隐藏整个视图以及导航控制器是模态视图的默认行为,所以请尝试在模态视图中单独导航栏进行导航。

你可以在这个链接进一步检查

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

 AddContactVC *addController =[self.storyboard instantiateViewControllerWithIdentifier:@"AddContactVC"]; UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:addController]; [self presentViewController:navigationController animated:YES completion: nil]; 

为我工作显示导航栏

强调和德文 –

当我开始阅读苹果文档来熟悉这个问题时,我注意到你正在使用的方法presentModalViewController:animated:似乎不赞成使用presentViewController:animated:completion: 也许你应该尝试使用该方法。

为了您的方便,请自己看看:

presentModalViewController:animated:引用

我会试着把一个快速的testing程序放在一起,看看我上面所说的是否是真的。 但给它一个镜头 – 也许它会帮助!

Xcode的模板非常接近你正在做的事情。 从结果,我不认为你应该试图执行[self.navigationController presentModalViewController:vc]和[self.navigationController dismissModalViewControllerAnimated:],而是简单地[自我presentModalViewController:]和[自我dismissModalViewControllerAnimated:]。

看看这个模板是如何为你自己做的,你可以在xcode 4.3中使用新的项目向导。 也许会提供一些指导:

Xcode新的项目向导实用程序模板

从该选项中select下一步,然后为testing项目命名,select“通用”,closures自动引用计数,然后点击,保存到您想要的位置。

现在,单击目标,并将部署目标切换到4.3(或更高版本,如果您愿意)以进行testing,然后切换到您的设备或iOS 4.3模拟器。

最后,在applicationDidFinishLaunching中replace下面的代码:withOptions:在创build的AppDelegate.m中:

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil] autorelease]; } else { self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController_iPad" bundle:nil] autorelease]; } UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController]; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES; 

现在,当我运行这个,它不隐藏导航栏。 并从模板创build的MainViewController.m中,您将看到它是如何呈现模式视图控制器的,并将其从控制器本身而不是从导航控制器中解除。 为了好的措施,使模板代码更像你自己的,进入MainViewController.m并删除设置模态视图控制器转换风格的行…

(当然,在iOS 5中,故事板,同样的事情都可以通过模式segues完成…这是我为了应用程序,我不支持5.0之前,提出了一个modalViewController在这个应用程序时尚。)

其中一个最好的解决scheme是使用这个类别MaryPopin https://github.com/Backelite/MaryPopin