无法将页面控制器添加到RBTabbedPageContainerViewController

时间:2016-08-03 22:06:42

标签: redbeard-ios

我正在尝试创建一个简单的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显然没有,因为它没有被添加到标签页容器中。

1 个答案:

答案 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应该“在飞行中”这样的事情吗?