【问题标题】:How to Reveal ViewController Storyboard Elements from a NavBarController inside of a TabBarController如何从 TabBarController 内的 NavBarController 显示 ViewController 故事板元素
【发布时间】:2016-10-23 12:14:31
【问题描述】:

所以我有一个以编程方式(不是通过情节提要)创建的 CustomTabBarController。在 viewDidLoad() 内部,我创建了一个 ProfileNavController,其视图控制器为 ProfileViewController(),也是以编程方式:

override func viewDidLoad() {
    super.viewDidLoad()

    // ProfileNavController <- ProfileController
    let profileController = ProfileViewController()
    let profileNavController = UINavigationController(rootViewController: profileController)
    let modifiedProfileNavController = UITabBarItem(title: "Profile", image: UIImage(named: ""), selectedImage: UIImage(named: ""))
    profileNavController.tabBarItem = modifiedProfileNavController

    // Tab-bar selector (ignore the "recentMessagesNavController", StackOverflow)
    viewControllers = [recentMessagesNavController, createDummyNavControllerWithTitle("Groups", imageName: ""), createDummyNavControllerWithTitle("Submit", imageName: ""), createDummyNavControllerWithTitle("Search", imageName: ""), profileNavController]
}

然后我创建了一个 Profile.storyboard 并将 View Controller 的类分配给身份检查器中的 ProfileViewController(在右侧列中)。在故事板视图控制器内部,我放置了一个标题为“Hello World”的标签。

问题是,每当我运行程序并单击“配置文件”选项卡时,标签(以及情节提要中的所有其他内容)都不会出现。如何让它们显示?

ProfileViewController.swift 供参考:

class ProfileViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.redColor()
        navigationItem.title = "Profile"
    }
}

【问题讨论】:

    标签: ios xcode swift storyboard viewcontroller


    【解决方案1】:

    您需要使用其故事板参考初始化 ProfileViewController

    let profileController = ProfileViewController()
    

    改成

    let profileController = UIStoryboard(name: "Profile", bundle: nil).instantiateInitialViewController()
    

    【讨论】:

    • 这部分有效,尽管我不得不将其修改为:let profileController = UIStoryboard(name: "Profile", bundle: nil).instantiateViewControllerWithIdentifier("profileViewController") as UIViewController,因为我假设视图控制器在情节提要中没有初始入口点。谢谢!
    猜你喜欢
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 2012-02-13
    • 1970-01-01
    • 2017-03-31
    • 2018-12-15
    • 2018-02-16
    相关资源
    最近更新 更多