<i id='kVHTD'><tr id='kVHTD'><dt id='kVHTD'><q id='kVHTD'><span id='kVHTD'><b id='kVHTD'><form id='kVHTD'><ins id='kVHTD'></ins><ul id='kVHTD'></ul><sub id='kVHTD'></sub></form><legend id='kVHTD'></legend><bdo id='kVHTD'><pre id='kVHTD'><center id='kVHTD'></center></pre></bdo></b><th id='kVHTD'></th></span></q></dt></tr></i><div id='kVHTD'><tfoot id='kVHTD'></tfoot><dl id='kVHTD'><fieldset id='kVHTD'></fieldset></dl></div>
  • <small id='kVHTD'></small><noframes id='kVHTD'>

      <legend id='kVHTD'><style id='kVHTD'><dir id='kVHTD'><q id='kVHTD'></q></dir></style></legend>
          <bdo id='kVHTD'></bdo><ul id='kVHTD'></ul>
      1. <tfoot id='kVHTD'></tfoot>

        向没有导航控制器的视图添加导航栏

        时间:2023-06-12
        <i id='5PZUp'><tr id='5PZUp'><dt id='5PZUp'><q id='5PZUp'><span id='5PZUp'><b id='5PZUp'><form id='5PZUp'><ins id='5PZUp'></ins><ul id='5PZUp'></ul><sub id='5PZUp'></sub></form><legend id='5PZUp'></legend><bdo id='5PZUp'><pre id='5PZUp'><center id='5PZUp'></center></pre></bdo></b><th id='5PZUp'></th></span></q></dt></tr></i><div id='5PZUp'><tfoot id='5PZUp'></tfoot><dl id='5PZUp'><fieldset id='5PZUp'></fieldset></dl></div>

          <small id='5PZUp'></small><noframes id='5PZUp'>

            <bdo id='5PZUp'></bdo><ul id='5PZUp'></ul>
              1. <legend id='5PZUp'><style id='5PZUp'><dir id='5PZUp'><q id='5PZUp'></q></dir></style></legend>
                  <tbody id='5PZUp'></tbody>
                <tfoot id='5PZUp'></tfoot>

                • 本文介绍了向没有导航控制器的视图添加导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个侧边菜单,可以滑出以显示表格视图,并且从那里我有使用显示视图控制器的 segues.segue 必须直接连接到视图控制器;我不能使用导航控制器.

                  如何在没有导航控制器的情况下添加带有条形按钮项的导航栏?

                  解决方案

                  虽然有几种聪明的方法可以回答您的问题.我只是以编程方式解决了它并在我的 viewWillAppear 中编写了以下代码(注意 - viewDidLoad 也可以,但不建议) -

                  <上一页>-(无效)viewWillAppear:(BOOL)动画{UINavigationBar *myNav = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];[UINavigationBar 外观].barTintColor = [UIColor lightGrayColor];[self.view addSubview:myNav];UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"样式:UIBarButtonItemStyleBordered目标:自己行动:无];UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"样式:UIBarButtonItemStyleBordered目标:自我行动:无];UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"导航标题"];navigItem.rightBarButtonItem = doneItem;navigItem.leftBarButtonItem = 取消项目;myNav.items = [NSArray arrayWithObjects: navigItem,nil];[UIBarButtonItem 外观].tintColor = [UIColor blueColor];}

                  因此,您有一个白色导航栏,其中包含蓝色栏按钮项,但没有导航控制器.同样,在您的情况下还有其他方法可以实现它.希望,这对您有所帮助.

                  输出 -

                  更新 -

                  添加图片 -

                  UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,10,32,32)];[myImage setImage:[UIImage imageNamed:@"image.png"]];self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myImage];[self.view addSubview:myImage];

                  I have a side menu that slides out to display a table view and from there I have segues that use the reveal view controller. The segue has to connect directly to the view controller; I can't use a navigation controller.

                  How do I add a navigation bar with a bar button item without a navigation controller?

                  解决方案

                  While there are several smart ways to answer your question. I just solved it programmatically and wrote the following code in my viewWillAppear (note - viewDidLoad is also okay, but not suggested) -

                  -(void) viewWillAppear:(BOOL)animated {
                  
                      UINavigationBar *myNav = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
                      [UINavigationBar appearance].barTintColor = [UIColor lightGrayColor];
                      [self.view addSubview:myNav];
                  
                  
                      UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
                                                                                     style:UIBarButtonItemStyleBordered
                                                                                    target:self
                                                                                    action:nil];
                  
                      UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                                   style:UIBarButtonItemStyleBordered
                                                                                  target:self action:nil];
                  
                  
                      UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
                      navigItem.rightBarButtonItem = doneItem;
                      navigItem.leftBarButtonItem = cancelItem;
                      myNav.items = [NSArray arrayWithObjects: navigItem,nil];
                  
                      [UIBarButtonItem appearance].tintColor = [UIColor blueColor];
                  }
                  

                  So, you have a white navigation bar with blue bar button items without a Navigation controller. Again, there are other ways to implement it in your case. Hope, this was helpful.

                  Output -

                  Update -

                  To add images -

                  UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,10,32,32)];
                  [myImage setImage:[UIImage imageNamed:@"image.png"]];
                  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myImage];
                  [self.view addSubview:myImage];
                  

                  这篇关于向没有导航控制器的视图添加导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:不断收到“对 &lt;ViewController&gt; 的开始/结束外观转换的不平衡调用" 下一篇:在 iPhone 导航栏上绘制自定义后退按钮

                  相关文章

                  <i id='iLx4n'><tr id='iLx4n'><dt id='iLx4n'><q id='iLx4n'><span id='iLx4n'><b id='iLx4n'><form id='iLx4n'><ins id='iLx4n'></ins><ul id='iLx4n'></ul><sub id='iLx4n'></sub></form><legend id='iLx4n'></legend><bdo id='iLx4n'><pre id='iLx4n'><center id='iLx4n'></center></pre></bdo></b><th id='iLx4n'></th></span></q></dt></tr></i><div id='iLx4n'><tfoot id='iLx4n'></tfoot><dl id='iLx4n'><fieldset id='iLx4n'></fieldset></dl></div>
                  <legend id='iLx4n'><style id='iLx4n'><dir id='iLx4n'><q id='iLx4n'></q></dir></style></legend>
                • <tfoot id='iLx4n'></tfoot>

                    <bdo id='iLx4n'></bdo><ul id='iLx4n'></ul>
                • <small id='iLx4n'></small><noframes id='iLx4n'>