ios - UINavigationBar 在 presentViewController 上消失 :animated:completion

标签 ios iphone objective-c

在一周的大部分时间里,我一直在用头撞墙,试图弄清楚这个错误是怎么回事,但我什么也想不通。我已经阅读了所有关于 Apple 开发人员的 View Controller 文档,在这里阅读了无数文章,等等。

我有 3 个 View Controller :一个基本 View Controller ,一个图像编辑 Controller (允许用户放大/平移图​​像,然后按下确定,将图像保存在边界内,通过将图像返回到基本 View 一个委托(delegate)方法,并将其推送到最后一个 View Controller ),最后是一个 BigPictureViewController,用户可以在其中与他保存的图像进行交互。

从基础 View Controller 调用 presentViewController:animated:completion 时,导航栏出现一瞬间,然后消失。我已经完全破坏了最终的 View Controller ,因此它只显示一个与您第一次创建 View Controller 时相同的空白屏幕,但导航栏仍然消失,所以我知道它不是 View Controller 编码中的东西。

这是来自图像编辑 Controller 的委托(delegate)(包含在基本 View Controller 中):

#pragma mark - camera view delegate
-(void)cameraView:(CameraViewController *)camView didReturnWithEditedImage:(UIImage *)image
{
    theImage = image;
    BPVCFlag = YES;
    [self.navigationController popViewControllerAnimated:YES];
}

接下来,在基础 View Controller 的 viewWillAppear 方法中,我检查标志以切换 segue:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (BPVCFlag)
    {
        BPVCFlag = NO;
        BigPictureViewController *bpvc = [[BigPictureViewController alloc] init];
        UIStoryboardSegue *seg = [[UIStoryboardSegue alloc] initWithIdentifier:@"pushitrealgood" source:self destination:bpvc];
        [self prepareForSegue:seg sender:self];
    }
}

最后,prepareForSegue 方法:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSString *id = [segue identifier];
    if ([id hasPrefix:@"pushit"]){
        BigPictureViewController *bpvc = segue.destinationViewController;
        bpvc.imageFromLibrary = theImage;
        [self presentViewController:bpvc animated:YES completion:nil];
    }
}

我已经尝试通过 self.navigationController 等呈现它,如果我使用的话,我可以让它坚持使用不同的导航 Controller

UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:bpvc];
[self.navigationController presentViewController:navCon animated:YES completion:nil];

但这似乎是一种非常 hacky 的方式,并没有真正解决问题,只是绕过了它。

抱歉文字墙,但我宁愿彻底而不是让人们蒙在鼓里。

TL;DR在presentViewController上,导航栏弹出一瞬间就消失了~

在此先感谢您的帮助/提示!

最佳答案

您的“hacky”解决方案实际上是正确的解决方案。当您调用 presentViewController:animated:completion: 时,呈现 View Controller 的导航 Controller 将不再可见。可以说,您正在添加一个新层。

如果您希望呈现的 View Controller (您的 BigPictureViewController)位于导航 Controller 中,您必须创建一个新的导航 Controller ,将新的 View Controller 作为根 Controller 传递。然后你展示导航 Controller 。

所以你想要这个:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSString *id = [segue identifier];
    if ([id hasPrefix:@"pushit"]) {
        BigPictureViewController *bpvc = segue.destinationViewController;
        UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:bpvc];
        bpvc.imageFromLibrary = theImage;
        [self presentViewController:navCon animated:YES completion:nil];
    }
}

关于ios - UINavigationBar 在 presentViewController 上消失 :animated:completion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20391627/

相关文章:

iphone - 随着表变大,Sqlite3 插入到非索引表需要更长的时间

iphone - 重新请求访问设备联系人

iphone - 如何像iOS 7 iPad App Store一样同时翻转和放大一个UIView?

objective-c - 我还应该复制/Block_copy ARC 下的 block 吗?

ios - 为标识符 (CELLNAME) 注册的 nib 无效 - nib 必须恰好包含一个顶级对象,该对象必须是 UITableViewCell 实例

objective-c - 如何更改 UIPageViewController 分页 curl 动画的方向

ios - 找不到 Realm 文件的加密 key

iphone - 使用 Cocoapods 时忽略 Xcode 警告

ios - 在动画中设置旋转方向时遇到问题

ios - 在 UIPasteBoard 中复制 NSAttributedString