菜鸟教程小白 发表于 2022-12-12 09:19:13

ios - 如何使用左侧的后退按钮创建导航栏?


                                            <p><p>在我的应用程序中,我尝试使用导航栏后退按钮从第二个 ViewController 导航到第一个 ViewController,但是在我的应用程序的 XIB 中将导航栏拖放到 ViewController 上时,我只能通过标题。</p>
<p>我做错了什么?我正在使用 Xcode 4.6。和 .xib 文件来设计 View 。这是我现在得到的:</p>
<p> <img src="/image/ettOY.png" alt="Navigation Bar Without Back Button"/> </p>
<p>这就是我要找的东西:</p>
<p> <img src="/image/boUtf.png" alt="Navigation Bar with Back Button"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>导航 Controller 提供了一个默认的导航栏和一个后退按钮。但是后退按钮标题的变化有点乱</p>
<p><strong>程序化</strong></p>
<pre><code>   UIStoryboard *astoryBoard=];
    ViewController2 *vc=;

   
    UIBarButtonItem *newBackButton = [ initWithTitle: @&#34;Master&#34; style: UIBarButtonItemStyleBordered target: nil action: nil];
    [ setBackBarButtonItem: newBackButton];
    ;
</code></pre>
<p>如果您使用的是 <strong>segue</strong>,请将这些行添加到父 VC</p>
<pre><code> UIBarButtonItem *newBackButton = [ initWithTitle: @&#34;Master&#34; style: UIBarButtonItemStyleBordered target: nil action: nil];
    [ setBackBarButtonItem: newBackButton];
</code></pre>
<p><strong>只是为了回来</strong></p>
<p>代码方面</p>
<pre><code>UIStoryboard *astoryBoard=];
      ViewController2 *vc=;
      ;
</code></pre>
<p>不是 Storyboard</p>
<p>创建第二个 VC 的实例,然后使用此代码</p>
<pre><code>YourViewController *VC=[initWithNibName:@&#34;yournibname&#34; bundle:];
      ;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何使用左侧的后退按钮创建导航栏?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15173926/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15173926/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何使用左侧的后退按钮创建导航栏?