【发布时间】:2017-08-10 11:50:53
【问题描述】:
我有 UITabBarController。从 Home 标签,我转到 ThankYouVC。
当我从ThankYouVC 中放松时,我想更改选定的选项卡。
我尝试过的:
HomeVC
@IBAction func unwindToMain(segue:UIStoryboardSegue) {
print("unwind")
self.tabBarController?.selectedIndex = 0
}
控制台日志打印unwind,但不改变 索引。
另一个尝试:
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
}
还是没有运气!!
帮帮我。
【问题讨论】:
-
你的
ThankYouVC怎么样?它是模态的“现在”转场吗?您的 TabBarController 是否在 NavigationController 中,并且您正在从 TabBar 推到ThankYouVC? -
我认为你的 self.tabBarController 是 nil ,这就是你的问题的原因。检查这个
-
@DonMag 我正在使用 Show(例如 Push)segue 转至ThankYouVC。不,TabBar 不在导航控制器内。
-
@MichałKwiecień,self.tabBarController 不是零。我在另一种情况下更改选项卡,效果很好
标签: ios swift swift3 uitabbarcontroller unwind-segue