加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – setNavigationBarHidden:在removeFromSuperview之后

发布时间:2020-12-14 17:20:44 所属栏目:百科 来源:网络整理
导读:我在我的Detail View Controller顶部添加了一个UIWebView子视图,它有一个导航栏.我想在WebView子视图中隐藏导航栏,并在从superview中删除时再次显示它,以便在查看WebView时有更多的屏幕空间. 我的代码的问题是添加子视图后导航栏被成功隐藏,但是当删除子视图
我在我的Detail View Controller顶部添加了一个UIWebView子视图,它有一个导航栏.我想在WebView子视图中隐藏导航栏,并在从superview中删除时再次显示它,以便在查看WebView时有更多的屏幕空间.

我的代码的问题是添加子视图后导航栏被成功隐藏,但是当删除子视图时尝试再次显示导航栏时它不起作用.

任何帮助将非常感激.谢谢.

这是我的代码:

// In InstrumentsDetailViewController.m

- (IBAction)edu1Link:(id)sender {

    _webViewController = [[WebViewController alloc]
                          initWithNibName:@"WebViewController" bundle:nil];

    [UIView beginAnimations:@"flipping view" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft
                           forView:self.view cache:YES];

    [self.view addSubview:_webViewController.view];

    [self.navigationController setNavigationBarHidden:YES animated:YES];

    [UIView commitAnimations];
}


// In WebViewController.m

- (IBAction) doneButton:(id)sender {

    [UIView beginAnimations:@"flipping view" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
                           forView:self.view.superview cache:YES];

    [self.view removeFromSuperview];

    [self.navigationController setNavigationBarHidden:NO animated:YES];

    [UIView commitAnimations];
}

解决方法

对于我在代码中看到的内容:
– 您正在向InstrumentDetailViewController实例主视图添加子视图.
– 子视图是WebViewController实例的主视图.

但是…… WebViewController永远不会被推送或弹出到您的导航堆栈.因此,您的WebViewController实例没有对navigationController的引用,并且调用[self.navigationController]会将您的setNavigationBarHidden:NO animated:YES消息发送给… nil

您可以:
– 将WebviewController实例推送/弹出到导航堆栈,因此它将引用navigationController.
要么
– 将您的WebViewController实例添加为InstrumentsDetailViewController的CHILD,然后调用

[[[self parentViewController] navigationController] setNavigationBarHidden:NO animated:YES];

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

搜索addChildViewController:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读