菜鸟教程小白 发表于 2022-12-12 12:11:58

ios - Objective-C:如何在 Xcode 中将 keywindow 设置为不同的 viewcontroller?


                                            <p><p>我正在使用 Storyboard 和此代码,但在我当前的 <code>viewConntroller</code> 中没有出现任何内容,而是在我的第一个 <code>viewConntroller</code> 中。任何人都可以将 <code>keywindow</code> 设置为我所在的当前 View 吗?</p>

<p>这是我用来显示我的 <code>UINavigationBar</code></p> 的代码

<pre><code>[[ keyWindow] addSubview:bar];
</code></pre>

<p>提前致谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您没有将 Viewcontroller 设置为 Window</p>

<p>你需要这样做:</p>

<pre><code> self.window = [ initWithFrame:[ bounds]];
    //self.window.backgroundColor = ;
    ;
</code></pre>

<p>这是添加 uinavigationcontroller 的方式:</p>

<p> <a href="https://stackoverflow.com/questions/4035370/add-a-uinavigationbar-to-a-uitableviewcontroller-without-a-uinavigationcontrolle" rel="noreferrer noopener nofollow">Add a UINavigationBar to a UITableViewController without a UINavigationController</a> </p>

<p>如果你想展示一个新的 ViewController </p>

<p>您只需使用 presentModalViewcontroller:</p>

<pre><code>UIViewController *vc = [ init];
;
</code></pre>

<p>//我都写好了,看看情况就可以用了</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Objective-C:如何在 Xcode 中将 keywindow 设置为不同的 viewcontroller?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/17493830/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/17493830/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Objective-C:如何在 Xcode 中将 keywindow 设置为不同的 viewcontroller?