呈现模态视图控制器隐藏导航栏 [英] Presenting a Modal View Controller hides the Navigation Bar

查看:152
本文介绍了呈现模态视图控制器隐藏导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  [self.navigationController setNavigationBarHidden:NO]; 

以及动画版本没有成功。



文档在方法中讲述了这一点

  presentModalViewController:animated:


在iPhone上的讨论区中,



和iPod touch设备,modalViewController的视图总是呈现全屏和将modalViewController属性设置为指定的视图控制器。调整其视图大小并将其附加到视图层次结构。但是,文档并没有提示我如何在关闭模态视图后撤消此过程。


有没有人遇到过这个问题并找到了解决方案?



编辑:我有同样的问题,这是我的具体情况:



在我的情况下,我在模态视图中呈现一个图像选择器控制器:通过导航控制器:

   - (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];
}
//保存图片
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
if(UI_USER_INTERFACE_IDIOM UIUserInterfaceIdiomPad){
[self.popoverController dismissPopoverAnimated:true];
} else {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
}


解决方案

确保你提交并从UINavigationController中关闭modalViewController,如下所示:

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

如果你的视图控制器实际上是在UINavigationController的堆栈,那么这是处理演示文稿的正确方式,解散模态视图控制器。如果你的UINavigationBar仍然隐藏,还有一些其他的事情,我们需要看到你的代码来确定发生了什么。



编辑



我将您的代码复制到我的一个应用程序,UIImagePickerController成功提交和关闭,我的UINavigationController的UINavigationBar仍然存在。我真的相信这个问题在你的架构的其他地方。如果你上传一个zip /一个示例项目,我会看看。


I have a navigation based app with a navigation bar, but there are a few instances where instead of pushing a view controller onto the stack, I need to present the view controller modally. The problem is that when I dismiss the modal view controller, everything functions as expected except that the navigation bar is hidden and the (parent view) has been resized, which is the expected behavior according to the docs. So I figured I could simply call a built-in method to unhide the navigation bar. I have already tried

[self.navigationController setNavigationBarHidden:NO];

as well as the animated version without success.

The documentation talks about this in the method

presentModalViewController: animated:

in the discussion section where it says,

On iPhone and iPod touch devices, the view of modalViewController is always presented full screen" and "Sets the modalViewController property to the specified view controller. Resizes its view and attaches it to the view hierarchy."However, the docs didn't clue me in as to how to undo this process after dismissing a modal view.

Has anyone else experienced this and found a solution?

Edit: I am having this same problem, so instead of asking my own question I am sponsoring a bounty on this one. This is my specific situation:

In my case, I am presenting an Image Picker in a Modal View Controller, over a Navigation Controller:

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

解决方案

Make sure you a presenting AND dismissing the modalViewController from the UINavigationController, like so:

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

If your view controller is actually on the UINavigationController's stack then this is the correct way to handle the presentation and dismissal of the modal view controller. If your UINavigationBar is still hidden, there is something else funky going on and we would need to see your code to determine what is happening.

Edit

I copied your code into an app of mine and the UIImagePickerController successfully presented and dismissed and my UINavigationController's UINavigationBar was still there. I truly believe that the problem lays elsewhere in your architecture. If you upload a zip w/ an example project I will take a look.

这篇关于呈现模态视图控制器隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆