私はこれについて検索しましたが、問題はまだあります。私はthis great questionを見つけましたが、残念ながらそれは私のためには機能しませんでした。私がNotificationCenter
と作業しているのはこれが初めてで、これを最初に使用する必要があるのは、ビューコントローラにデータを渡したいときに、XLPagerTabStripのタブの下に表示されます。私はNotificationCenter.default.addObserver(self, selector: #selector(gotDocID), name: Notification.Name("docID"), object: nil)
NotificationCenterがセレクタを呼び出さない
セレクタメソッドを呼んでいるこの通知を観察するために作ったクラスで
if let doc_ID = mainDoctorsArray[sender.tag].doctors_id {
NotificationCenter.default.post(name: Notification.Name("docID"), object: nil, userInfo: ["value" : doc_ID])
}
されています:だからここ
は、私は通知を掲示しています方法です
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)
}
}
私はまた、オブザーバーを次のように追加しようとしました: NotificationCenter.default.addObserver(self, selector: #selector(AvailableViewController.gotDocID(notification:)), name: Notification.Name("docID"), object: nil)
しかし同じ結果です。
func gotDocID(notification:NSNotification)
が呼び出されていないという問題があります。通知を掲示される
UPDATE
クラスViewController.swift
あり、観察者を持つクラスは、私はNotificationCenter.default.addObserver(self, selector: #selector(AvailableViewController.gotDocID(notification:)), name: Notification.Name("NotificationIdentifier"), object: nil)
にオブザーバーを変更したと、このエラーが生成されたコメントに基づいてAvailableViewController.swift
です。 また、私も同じエラーが表示されます。あなたがデータを投稿して取得するために以下のコードを使用することができます
Value of type 'AvailableViewController' has no member 'gotDocID'
を.doctors_id [sender.tag] mainDoctorsArrayのnullcheck結果は何ですか? –
あなたはそれを同じクラスか別のクラスで観察していますか? – karthikeyan
他のクラスの@karthikeyan –