iOS-swift 导航 Controller 样式不正确

标签 ios swift uinavigationcontroller

我的代码遇到以下问题:

在我的应用程序上,我有一个导航 Controller ,并且我根据我使用此功能呈现的 View Controller 来设置栏的样式:

func styleNavBar(barColor: String){

    let logo = UIImage(named: "logo-sura.pdf")
    let imageView = UIImageView(image:logo)
    self.navigationItem.titleView = imageView

    switch barColor {
    case "Dark":
        self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
        return
    case "Light":
        self.navigationController?.navigationBar.barTintColor = UIColor(netHex: 0x1CBBE1)
        return
    default:
        return
    }
}

它按照底部 View Controller 的预期工作(通过 segue 呈现)-我附加了图像-Story board that shows teh viewcontroller flow但在与 tabBar 关联的标签栏上,它不会显示 Logo 或导航项目。

任何关于我缺少什么的指针。

最佳答案

看到你的 Storyboard后,我建议执行以下操作:

  1. 实例化您的标签栏 Controller 并呈现它。

  2. 将每个选项卡栏 subview Controller 嵌入导航 Controller 中。正如 this answer 中所建议的

你的 Storyboard将如下所示:

enter image description here

显示标签栏 Controller :

    @IBAction func buttonPressed(sender: AnyObject) {

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let tabBarController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
        self.presentViewController(tabBarController,animated:true, completion:nil)
    }

然后在你 child 的 vc 中

    override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

        let logo = UIImage(named: "logo")
        let imageView = UIImageView(image:logo)
        self.navigationItem.titleView = imageView

    }

请告诉我它是否适合您。

关于iOS-swift 导航 Controller 样式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36992537/

相关文章:

ios - Xcode如何调试发送到实例的无法识别的选择器

ios - 在WatchOS上使用AVAudioEngine录音时禁止播放

ios - 在 iOS 中使用照片保存位置 exif 数据

ios - swift 。在 ViewController 之间转换而不在返回时关闭它们

iphone - Cocos2dx iOS App 崩溃

iphone - 在 ios 5 的 MP 音乐播放器 Controller 中获得错误的播放状态

iphone - 代表 uitableview 中的必填字段

swift - Alamofire 请求在 Swift 4 项目中不起作用

ios - UINavigationController 中的 UITableViewController 来表示未知深度的树结构

ios - 带有后退按钮的导航栏中的 UISegmentedControl