更新时间:2023-11-28 08:44:40
由于您是以编程方式创建LoginViewController
的,因此我假定TabBarController
默认为storyboard
的rootViewController
.您在AppDelegate
中所需要做的就是这个.
Since you are creating your LoginViewController
programatically so I assume that the TabBarController
would be the rootViewController
of the storyboard
by default. All you need to do in your AppDelegate
is this.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let token = UserDefaults.standard.object(forKey: "token")
if token == nil {
//***************
//Create your LoginViewController and make it the rootViewController
//***************
}
return true
}
注意:我使用的是Swift 3
,因此语法上会有细微的差别.
Note: I'm using Swift 3
so there will be a slight difference in the syntax.