菜鸟教程小白 发表于 2022-12-11 18:06:54

ios - 在 Swift 2.3 中导航到 UIViewController


                                            <p><p>我正在尝试使用 Swift 2.3 导航到 <code>UIViewController</code>。更准确地说,我正在尝试重新加载当前处于事件状态的 <code>UIViewController</code>。我不知道用户当前激活了哪个 View ,所以必须动态定义。</p>

<p>我尝试了几种方法,但它们都会导致编译或运行时错误。</p>

<p>这样的事情可能吗?</p>

<pre><code>let activeViewIdentifier = ??? // Get currently active view identifier as a string
self.performSegueWithIdentifier(activeViewIdentifier, sender:self)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你可以这样:</p>

<p> objective-C :</p>

<pre><code>self.navigationController.topViewController.restorationIdentifier
</code></pre>

<p> swift :</p>

<pre><code>self.navigationController?.topViewController?.restorationIdentifier
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 Swift 2.3 中导航到 UIViewController,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40741777/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40741777/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 Swift 2.3 中导航到 UIViewController