我在 github 上发现了这个很棒的 TabBar,叫做 FoldingTabBar.iOS我已经导入并且我可以调用和使用但是有一个我不知道如何快速使用的初始化器我真的希望有人能帮助我,在示例项目中嘿调用 AppDelegate.m
示例中的 Object-C:
YALFoldingTabBarController *tabBarController = (YALFoldingTabBarController *) self.window.rootViewController;
当我尝试在我的 AppDelegate 中创建 YALFoldingTabBarController 时,我有以下选项:
我在 Swift 中的尝试:
YALFoldingTabBarController()
YALFoldingTabBarController(coder: NSCoder)
YALFoldingTabBarController(nib: String bunble:NSBundle)
(sorry this is coming from memory so my be slightly wrong, but they are the default initializers for UIViewController)
我试试
var Controller = YALFoldingTabBarController() controller = self.window.rootViewController 为! YALFoldingTabBar Controller 错误无法转换
var controller = YALFoldingTabBarController(self.window.rootViewController)
No such initializer
关于我如何从原始的 Object-C 初始化器到 Swift 初始化器,有什么想法吗?
提前致谢
最佳答案
如果 Root View Controller 的类在 Interface Builder 中设置为 YALFoldingTabBarController,则不需要显式初始化。
ObjC 行的 Swift 等价物
YALFoldingTabBarController *tabBarController = (YALFoldingTabBarController *) self.window.rootViewController;
是
let tabBarController = self.window.rootViewController as! YALFoldingTabBarController
关于ios - 理解如何在 Swift 中初始化 Object-c 对象的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31733580/