Ich habe darüber gesucht, aber das Problem existiert immer noch für mich. Ich fand this great question aber leider hat es nicht für mich funktioniert. Dies ist das erste Mal, dass ich mit NotificationCenter
arbeite und die Notwendigkeit, diese zuerst zu verwenden, tritt auf, wenn ich Daten an einen Viewcontroller unter einer Registerkarte XLPagerTabStrip übergeben wollte.NotificationCenter ruft den Selektor nicht an
Also hier ist, wie ich die Mitteilung bin Entsendung:
if let doc_ID = mainDoctorsArray[sender.tag].doctors_id {
NotificationCenter.default.post(name: Notification.Name("docID"), object: nil, userInfo: ["value" : doc_ID])
}
In der Klasse I für die Beobachtung dieser Benachrichtigung gemacht habe ich NotificationCenter.default.addObserver(self, selector: #selector(gotDocID), name: Notification.Name("docID"), object: nil)
Der Selektor Methode bin Aufruf ist:
func gotDocID(notification:NSNotification) {
let userInfo:Dictionary<String,String> = notification.userInfo as! Dictionary<String,String>
if let item = userInfo["value"] {
getDoctorDetails(docID: Int(item)!)
//print(item,self)
}
}
Ich habe auch versucht, Beobachter hinzufügen als: NotificationCenter.default.addObserver(self, selector: #selector(AvailableViewController.gotDocID(notification:)), name: Notification.Name("docID"), object: nil)
aber immer noch das gleiche Ergebnis.
Das Problem ist, dass func gotDocID(notification:NSNotification)
nicht aufgerufen wird.
UPDATE
Klasse, die die Benachrichtigung Entsendung ist ViewController.swift
und die Klasse, die den Betrachter hat, ist AvailableViewController.swift
auf einen Kommentar Basierend I Beobachter NotificationCenter.default.addObserver(self, selector: #selector(AvailableViewController.gotDocID(notification:)), name: Notification.Name("NotificationIdentifier"), object: nil)
und dieser Fehler geändert haben wird erzeugt. und auch durch die folgende Folge bekomme ich den gleichen Fehler.
Value of type 'AvailableViewController' has no member 'gotDocID'
was ist das nullcheck Ergebnis mainDoctorsArray [sender.tag] .doctors_id? –
wo beobachtest du dieselbe Klasse oder eine andere Klasse? – karthikeyan
@karthikeyan in einer anderen Klasse –