我在view controllers
中嵌入了2个navigation bar controller
。此外,每个视图控制器都有一个覆盖整个视图的表视图。
我遇到的问题是back button
中的2nd view controller
(这是左栏按钮项目)不可见虽然我可以点按左上角屏幕的一角,它将我带回到前一个视图控制器。因此,该按钮不可见。
我的App Delegate中有这个代码,因为我需要更改导航栏标题标题的外观。这是否以某种方式覆盖了我的导航栏?
- 的 AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//change navigation bar appearance
//--background color
UINavigationBar.appearance().barTintColor = UIColor.white
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UINavigationBar.appearance().isTranslucent = false
//--title color
let fontColor = UIColor(red: 80/255.0, green: 80/255.0, blue: 80/255.0, alpha: 1.0)
let font = UIFont(name: "Verdana-Bold", size: 20)!
let attributes: [String: AnyObject] = [
NSFontAttributeName: font,
NSForegroundColorAttributeName: fontColor
]
UINavigationBar.appearance().titleTextAttributes = attributes
return true
}
我确实在Attribute Inspector
Navigation Controller Scene
中验证了属性 '显示导航栏 是checked
。< / p>
我甚至尝试以编程方式向1rst view controller
添加刷新按钮,我可以在控制台中看到print语句,这意味着当我按左上角时,控制台会打印 “刷新按钮按下“ ,但即使它起作用,该按钮也不可见。
- 的 FirstViewController.swift
// MARK: - Target Action functions
@IBAction func refreshAction(_ sender: UIButton) {
print("Refresh Button Pressed")
//let _ = self.navigationController?.popViewController(animated: true)
}
func setNavigationBarAttributes() {
//set title for navigation bar (the appearance was changed in App Delegate)
self.navigationItem.title = "NYC Schools"
//refresh button
let refreshButton = UIButton(type: .custom)
refreshButton.setImage(UIImage(named: "back_button.png"), for: .normal) // Image can be downloaded from here below link
refreshButton.setTitle("Refresh", for: .normal)
refreshButton.setTitleColor(refreshButton.tintColor, for: .normal) // You can change the TitleColor
refreshButton.addTarget(self, action: #selector(self.refreshAction(_:)), for: .touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: refreshButton)
}
答案 0 :(得分:0)
我认为2nd view controller
中隐藏的,后退按钮的问题在于您将导航栏barTintColor
设置为白色,并将tintColor
设置为白色。这会在白色导航栏上显示一个白色后退按钮 - 使其不可见!
在AppDelegate
:
UINavigationBar.appearance().barTintColor = UIColor.white
UINavigationBar.appearance().tintColor = UIColor.blue
至于1st view controller
上的刷新按钮 - 我认为有两种可能性可以让您无法看到它: