gpt4 book ai didi

ios - swift 3 : UITabBarController change tab on unwind

转载 作者:行者123 更新时间:2023-11-28 10:52:13 25 4
gpt4 key购买 nike

我有 UITabBarController。从 Home 选项卡,我转到 ThankYouVC

当我从 ThankYouVC 放松时,我想更改选定的选项卡。

我尝试过的:

首页VC

@IBAction func unwindToMain(segue:UIStoryboardSegue) {
print("unwind")
self.tabBarController?.selectedIndex = 0
}

控制台日志打印展开,但不会更改索引

另一个尝试:

enum Notifications: String, NotificationName {
case QRDoneNotification
}

override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(unwindCallBack), name: Notification.Name("QRDoneNotification"), object: nil)
}

@IBAction func unwindToMain(segue:UIStoryboardSegue) {
print("unwind")
NotificationCenter.default.post(name: Notifications.QRDoneNotification.name, object: nil)
}

func unwindCallBack() {
self.tabBarController?.selectedIndex = 0
}

还是不走运!!

帮帮我。

最佳答案

问题是 unwind segue unwinds 到包含函数的 View Controller 。所以这就是你的结局。

一个解决方案:继承 UITabBarController 并将您的展开转场放在那里。

class MyTabBarController: UITabBarController {

@IBAction func unwindToMain(segue:UIStoryboardSegue) {
print("Unwinding to the custom tab bar controller...")
selectedIndex = 1
}

}

因此,将该类添加到您的项目中...将当前 UITabBarController 的自定义类设置为 MyTabBarController...将您的退出/展开转场分配给这个新转场,并且不要忘记删除现有的 unwindToMain() 函数并解除连接。

关于ios - swift 3 : UITabBarController change tab on unwind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45612969/

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