我在一个视图中编写了发送通知,并在另一个视图上接收但是它无效。我已经按照NSNotificationCenter addObserver in Swift的代码进行了操作,但无法实现,任何建议都会非常感激
这是我的代码
ViewController 1或发送通知视图
import UIKit
class HomeView: UIViewController {
@IBOutlet weak var subscribers: CustomButton!
@IBOutlet weak var newResig: CustomButton!
override func viewDidLoad() {
}
override func viewWillDisappear(animated: Bool) {
}
@IBAction func languageEnglish(sender: AnyObject) {
subscribers.setTitle("SUBSCRIBERS", forState: .Normal)
newResig.setTitle("NEW REGISTRATION", forState: .Normal)
}
@IBAction func languageArabic(sender: AnyObject) {
subscribers.setTitle("المشتركين", forState: .Normal)
newResig.setTitle("اشتراك جديد", forState: .Normal)
NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)
}
}
ViewController 2或接收通知视图
import UIKit
class Subscription: UIViewController {
@IBOutlet weak var scheduling_Appointment: UILabel!
@IBOutlet weak var deliveryMedicine: UILabel!
@IBOutlet weak var visitDoc: UILabel!
@IBOutlet weak var medicalHelp: UILabel!
@IBOutlet weak var ChronicDiseases: UILabel!
@IBOutlet weak var contactUs: UILabel!
override func viewDidLoad() {
self.title = "Subscribers"
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(Subscription.methodOfReceivedNotification(_:)), name:"NotificationIdentifier", object: nil)
}
func methodOfReceivedNotification(notification: NSNotification){
//Take Action on Notification
scheduling_Appointment.text = "حجز كشف جديد"
deliveryMedicine.text = "توصيل الادوي"
visitDoc.text = " زيارة الاطباء"
medicalHelp.text = "التحدث المباشر"
ChronicDiseases.text = "الامراض المزمنة"
contactUs.text = "اتصل بنا"
}
}