我想将Tabbar添加到我的应用程序中。但是当我尝试添加它时,它会在标题中给出错误。如何激活Tabbar功能?
public extension UIViewController {
public func setTabBarSwipe(enabled: Bool) {
if let swipeTabBarController = tabBarController as? SwipeableTabBarController {
swipeTabBarController.isSwipeEnabled = enabled
}
}
}
class MainTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(SwipeableTabBarController)
}
您无法在此处将用户定义的类型SwipeableTabBarController
选项卡添加为子视图
view.addSubview(SwipeableTabBarController)
你需要添加一个像这样的实例
let vc = SwipeableTabBarController()
self.addChild(vc)
vc.view.frame = self.view.bounds
view.addSubview(vc.view)
vc.willMove(toParent:self)
如果你的tabBarController是应用程序的根视图控制器,请使用它。
if let window = UIApplication.shared.keyWindow,
let tabBar = window.rootViewController as? SwipeableTabBarController {
tabBar.isSwipeEnabled = enabled
}