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

ios - 标签栏 Controller : executing code before switching view


                                            <p><p>我想在显示另一个 View 之前执行一些代码,当用户在标签栏 Controller 中推送具有不同 View 的栏项时。</p>

<p>我正在尝试在我的类(class)中使用委托(delegate):</p>

<p><code>@interface HPAAddCarOverallInfoTableViewController () <UITabBarControllerDelegate></code></p>

<p>我通过使用委托(delegate)方法接近了我的问题:</p>

<pre><code>-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
</code></pre>

<p>不幸的是,<code>(UIViewController *)viewController</code> 包含有关所选 ViewController 的信息,而不是有关从哪个 ViewController 中选择它的信息。</p>

<p><strong>问题:</strong>
你能告诉我吗,拜托。如何获取信息,这些信息将告诉我从哪个显示 View 中推送了标签栏项?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以实现 <a href="https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITabBarControllerDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITabBarControllerDelegate/tabBarController:shouldSelectViewController:" rel="noreferrer noopener nofollow"><code>-tabBarController:shouldSelectViewController:</code></a>在您的标签栏 Controller 委托(delegate)中。您将在实际选择新 ViewController 之前收到该消息,因此您可以找出 <em>当前</em> 选择了哪个 ViewController ,也许将其保存在 ivar 或其他东西中。也许你可以用那个方法做你需要做的工作,或者你可能会等到 <code>...didSelectViewController:</code> 消息,但无论哪种方式,你都会知道旧的和新的 ViewController .</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 标签栏 Controller: executing code before switching view,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26785260/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26785260/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 标签栏 Controller : executing code before switching view