[英]How do I change the initial tab bar selection in swift?
在嘗試找到解決方案時,我遇到了以下答案:
[ https://stackoverflow.com/a/10441200/4856759 ]
它似乎完成了我想要的,但是在目標C中:
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
tabBar.selectedIndex = 0;
如何迅速做到這一點? 我的第一次嘗試返回一個錯誤:
無法轉換表達式的類型'$ T4 ??' 鍵入“ UITabBarController”
var tabBar: UITabBarController = self.window?.rootViewController
tabBar.selectedIndex = 1
為我工作! 您只需要添加as! UITabBarController
as! UITabBarController
:
var tabBar: UITabBarController = self.window?.rootViewController as! UITabBarController
tabBar.selectedIndex = 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.