![](/img/trans.png)
[英]NSNotification not receiving in View Controller from appDelegate
[英]Executing a selector after receiving NSNotification calls my view controller's deinit
每當我收到NSNotification並執行相應的選擇器時,都會調用我的視圖控制器的deinit
函數。 這是我的視圖控制器的代碼:
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "initModels", name: "xyz.notification", object: nil)
}
func initModels(){
print("Received notification to init models")
}
deinit {
print("De-init view controller")
NSNotificationCenter.defaultCenter().removeObserver(self)
}
每個視圖控制器都收到通知,它正常執行“ initModels”,但隨后將直接調用“ deinit”! 這是在控制台上打印的內容:
Received notification to init models
De-init view controller
我檢查了與多線程相關的所有內容。 通知在主線程上發送,並在主線程上執行。
天啊! 由於我不知道的原因,當選擇器名稱以“ init”開頭時,它將導致我的視圖控制器的deinit
函數被調用!
這是我嘗試過的函數名稱:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.