【问题标题】:Understanding UITabBarController subclass initializer code in Obj- C理解 Obj-C 中的 UITabBarController 子类初始化代码
【发布时间】:2015-06-21 06:05:29
【问题描述】:
我在 GitHub 上找到了一个项目,并试图在我的 Swift 项目中实现它。我坚持以下行的语法:
YALFoldingTabBarController *tabBarController = (YALFoldingTabBarController *) self.window.rootViewController;
我不知道如何在 AppDelegate 中初始化这一行。任何有关此行含义的帮助和解释将不胜感激。该项目可以在here找到。
【问题讨论】:
标签:
ios
objective-c
swift
appdelegate
【解决方案1】:
该代码应该翻译成类似的东西
let tabBarController: YALFoldingTabBarController = self.window.rootViewController as! YALFoldingTabBarController
希望有帮助:)
【解决方案2】:
if let tabBarController = self.window.rootViewController as? YALFoldingTabBarController {
}
不过,这条线并没有多大作用。它所做的只是从UIViewController 转换为YALFoldingTabBarController。