我正在尝试创建一个简单的TabBar控制器,但我无法向其添加页面。
class TabbedPageContainerViewController: RBTabbedPageContainerViewController {
override func viewDidLoad() {
super.viewDidLoad()
let success = addPageController(MapViewController(), withTitle: "Fancy Tab")
print("addPageController: \(success)")
print("pages: \(pageControllerCount)")
print("first item: \(pageControllerAtIndex(0))")
}
...
导致空白屏幕和控制台输出:
addPageController: true
pages: 0
first item: nil
MapViewController
本身就是RBPageViewController
:
class MapViewController: RBPageViewController, MGLMapViewDelegate {
...
MapViewController
已正确实例化。它viewDidLoad
被解雇了,viewDidAppear
显然没有,因为它没有被添加到标签页容器中。
答案 0 :(得分:0)
我自己通过在TabbedPageContainerViewController
applicationDidFinishLaunching
中实例化这两个类来解决它:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let tabbedPageContainerViewController = TabbedPageContainerViewController()
tabbedPageContainerViewController.addPageController(MapViewController(), withTitle: "Fancy Tab"))
// present tabbed page controller
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = tabbedPageContainerViewController
window?.makeKeyAndVisible()
return true
}
但为什么这有必要呢?难道我没有在某处看到Redshift应该“在飞行中”这样的事情吗?