I'm trying to pass data between tab bar controllers for the firts time, but it doesn't work. First Controller:
class FirstViewController: UIViewController {
@IBOutlet weak var sentNotificationLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateNotificationSentLabel:", name: mySpecialNotificationKey, object: nil)
}
@IBAction func notify() {
NSNotificationCenter.defaultCenter().postNotificationName(mySpecialNotificationKey, object: nil, userInfo:["message":"Something"])
}
func updateNotificationSentLabel(notification:NSNotification) {
let userInfo:Dictionary<String,String!> = notification.userInfo as Dictionary<String,String!>
let messageString = userInfo["message"]
sentNotificationLabel.text = messageString
}
}
Here it works ok, the sentNotificationLabel.text is "Something"
Second Controller is similiar, but he's not receiving any notification.
class SecondViewController: UIViewController {
@IBOutlet weak var notificationLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateLabel:", name: mySpecialNotificationKey, object: nil)
}
func updateLabel(notification:NSNotification) {
let userInfo:Dictionary<String,String!> = notification.userInfo as Dictionary<String,String!>
let messageString = userInfo["message"]
notificationLabel.text = messageString
}
}
What I am doing wrong? How to change that?