gpt4 book ai didi

ios - 在 tabbarcontroller 中更改选项卡时如何调用 Controller ? ( swift )

转载 作者:行者123 更新时间:2023-11-28 06:08:54 25 4
gpt4 key购买 nike

我在选项卡栏 Controller 和歌曲 Controller 中有一个搜索选项卡。当用户单击歌曲 Controller 中的按钮之一并开始搜索时,我想跳转到搜索选项卡。我正在使用此代码更改选项卡

 self.tabBarController?.selectedIndex = 0

上面的代码有效,但我想在更改标签时调用搜索标签中的搜索功能。

最佳答案

您将通知在您的 ViewController 中实现 UITabBarControllerDelegate 协议(protocol)

您需要在 viewDidLoad 中为您的 viewController 添加这一行

self.tabBarController?.delegate = self

并实现UITabBarControllerDelegate协议(protocol)的这个方法

public func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)

当在您的 tabBarController 中选择一个新的 viewController 时,您将收到通知

关于ios - 在 tabbarcontroller 中更改选项卡时如何调用 Controller ? ( swift ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47303093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com