问题描述
我遇到了问题
tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
委托解雇.问题在于当我尝试使用 self.tabBarController?.selectedIndex 并以编程方式更改选项卡时.一旦我使用 selectedIndex 并返回上一个选项卡并单击 tabBarItem ,委托就不再触发.仅当我不使用 selectedIndex 时委托才会触发,但是一旦我使用它,即使我点击 tabBar 项目,didSelect 委托也不会再次触发.有什么建议?感谢您的帮助!
delegate firing. The problem lies when I try to use self.tabBarController?.selectedIndex and change a tab programmatically. Once I use selectedIndex and go back to a previous tab and click on the tabBarItem the delegate does not fire anymore. Delegate only fires if I do not use selectedIndex but once i use it the didSelect delegate never fires again even if I tap on the tabBar item. Any suggestions? Thanks for your help!
推荐答案
你需要像下面这样以编程方式调用委托例如.我需要选择位于第 4 个索引的 SettingsTab,我可以使用此代码实现.这里 didSelect 也以编程方式调用
You need to call delegate programmatically like belowFor eg. I need to select SettingsTab which is at 4th index, i can achieve using this code. Here didSelect is also called programmatically
if let tabbarC = self.tabBarController{
tabbarC.selectedIndex = 4
let setting = tabbarC.viewControllers![4]
self.tabBarController(tabbarC, didSelect: setting)
}
希望这会有所帮助!
这篇关于tabBarController didSelect 没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!