我正在向SecondViewController发布通知。它看起来像:
@IBAction func NotifyButton(sender:AnyObject)
{
NSNotificationCenter.defaultCenter().postNotificationName("test", object: nil)
}
在我的SecondViewController中,我观察到此通知。
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "Noti", name: "test", object: nil)
}
我的选择方法在这里:
func Noti(notification:NSNotification)
{
println( "Ohhhh Notification aaya ...are wa")
}
but control is never reach to selector method. Thanks
答案 0 :(得分:-1)
已发送(发布)通知
NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)
接收(获取)通知
NSNotificationCenter.defaultCenter().addObserver(self, selector: "methodOfReceivedNotification:", name:"NotificationIdentifier", object: nil)
删除通知
NSNotificationCenter.defaultCenter().removeObserver(self, name: "NotificationIdentifier", object: nil)
收到通知的方法
func methodOfReceivedNotification(notification: NSNotification){
//Action take on Notification
}