Commit a9b4e6fb by Daniel Dahan

fixed issue where UINavigationItem.title was not updating the titleLabel text

parent cb12b1bf
...@@ -449,6 +449,7 @@ public class NavigationBar : UINavigationBar { ...@@ -449,6 +449,7 @@ public class NavigationBar : UINavigationBar {
} }
item.hidesBackButton = false item.hidesBackButton = false
item.setHidesBackButton(true, animated: false) item.setHidesBackButton(true, animated: false)
item.addTitleObserver()
} }
/** /**
......
...@@ -30,10 +30,19 @@ ...@@ -30,10 +30,19 @@
import UIKit import UIKit
/// A context for observing the title property for the NavigationItem.
private var MaterialNavigationItemTitleContext: UInt8 = 1
/// A memory reference to the NavigationItem instance. /// A memory reference to the NavigationItem instance.
private var MaterialAssociatedObjectNavigationItemKey: UInt8 = 0 private var MaterialAssociatedObjectNavigationItemKey: UInt8 = 0
public class MaterialAssociatedObjectNavigationItem { public class MaterialAssociatedObjectNavigationItem {
/**
A boolean indicating whether keys are being observed
on the UINavigationItem.
*/
internal var observed: Bool = false
/// Back Button. /// Back Button.
public var backButton: IconButton? public var backButton: IconButton?
...@@ -106,6 +115,22 @@ public extension UINavigationItem { ...@@ -106,6 +115,22 @@ public extension UINavigationItem {
} }
} }
/// Sets the title property to be observed.
internal func addTitleObserver() {
if !item.observed {
item.observed = true
addObserver(self, forKeyPath: "title", options: .New, context: &MaterialNavigationItemTitleContext)
}
}
public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &MaterialNavigationItemTitleContext {
titleLabel.text = change?["new"] as? String
} else {
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
}
}
/// Title Label. /// Title Label.
public internal(set) var titleLabel: UILabel { public internal(set) var titleLabel: UILabel {
get { get {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment