zoukankan      html  css  js  c++  java
  • UIViewController自带的NavigationViewController不显示的问题

        问题: 妹子最近在写代码的时候想使用一下UIViewController自带的navigationVIewController的时候发现无论在navigation中写入什么代码,界面都没有显示,通过分层图发现界面上压根就没有这个navigationBar的容器啊,哪里去了,哪里去了?

        例子:先贴出妹子错误的示范:

        if (self.navigationController) { // 去掉这一层也是错误的示范哦

            self.navigationItem.title = @"姨吗爱买";

            self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@""] style:UIBarButtonItemStylePlain target:self action:@selector(selector)];

        }

      

       原因:查阅了navigationController的属性,发现没有在本界面设置某一个属性就可以使得navigationBar出来,而问题的根本在这里

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = navigationController;

        只有在APPdelegate中添加了这句话,并且保证self.window.rootViewController = navigationController;才会创建出navigationBar;

       所以如果是简单的demo的话是可以直接这样使用的,但是一个复杂的demo中是需要用到各种视图控制器,比如tabBar这样两者就会发生冲突,面对这种情况下,小伙伴们要乖乖的自定义一个navigationViewController,添加到UITableView中,然后自定义这个navigationViewController,代码如下

       例如:

    @property (nonatomic, strong) UIView *tableHeaderView;

    - (UITableView *)tableView

    {

        if (!_tableView) {

            _tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];

            _tableView.tableHeaderView = self.tableHeaderView;

        }

        return _tableView;

    }

    - (UIView *)tableHeaderView

    {

        if (!_tableHeaderView) {

            _tableHeaderView = [[UIView alloc]init];

            _tableHeaderView.frame = CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 100);

            _tableHeaderView.backgroundColor = [UIColor clearColor];

        }

        return _tableHeaderView;

    }

       虽然写完以后觉得很简单,但是之前一直找不到原因啊,所以记录下来希望能帮到需要的小伙伴

  • 相关阅读:
    UWP关于图片缓存的那些破事儿
    UWP中的文件相关操作
    数据结构-快速排序(C#实现)
    C#与Swift异步操作的差异
    Windows环境下使用Clover四叶草引导双硬盘安装OSX 10.11.5原版镜像
    Winform以任意角度旋转PictureBox中的图片的方法
    Xcode调用旧版本库出现Undefined symbols for architecture x86_64: ld: symbol(s) not found for architecture x86_64
    做WP程序时遇到的一些问题及解决方法
    WInform关闭程序的几种方法以及区别。
    显示在标题上的进度条
  • 原文地址:https://www.cnblogs.com/lepus/p/5867554.html
Copyright © 2011-2022 走看看