NSNotification Random Like 无法识别的异常
NSNotification Random Like unrecognized exception
我正在尝试使用 NSNotification 在两个 swift class 之间进行通信。我不知道我做错了什么,但在其他通知工作正常的情况下,其中一个通知不断将无法识别的选择器随机发送到实例异常。随机我的意思是每次我执行该代码异常是相同的,但 class 引用是不同的,如 __CALayer、__NSArray、__NSSet 等,我什至不使用那些class直接。有帮助吗?
这里是观察者class初始化方法:
override init() {
super.init()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "downloadChapter:", name: "downloadListNotification", object: DisplayMangaViewController.self)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "downloadChapter:", name: "downloadListNotification", object: DownloadRequestListViewController.self)
}
还有我在里面的 post 通知 :
let userInfo = ["downloadList" : self.selectedChapters , "mangaName" : self.obtainedMangaName]
let notification = NSNotification(name: "downloadListNotification", object: DownloadRequestListViewController.self, userInfo: userInfo as [NSObject : AnyObject])
NSNotificationCenter.defaultCenter().postNotification(notification)
这是一个异常示例:
2015-09-05 19:49:45.598 TurkİşManga[12708:58814] -[__NSArrayM
downloadChapter:]: unrecognized selector sent to instance
0x7fbf9c80dd90 2015-09-05 19:49:45.600 TurkİşManga[12708:58814] ***
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSArrayM downloadChapter:]:
unrecognized selector sent to instance 0x7fbf9c80dd90'
这里还有 downloadChapter 方法的草稿:
func downloadChapter(notification : NSNotification){}
显然我的观察者 class 被释放,因此当通知发布时,任何观察者都会被释放。所以在发布任何通知之前,从观察者 class 创建一个实例已经解决了这个问题。谢谢。
我正在尝试使用 NSNotification 在两个 swift class 之间进行通信。我不知道我做错了什么,但在其他通知工作正常的情况下,其中一个通知不断将无法识别的选择器随机发送到实例异常。随机我的意思是每次我执行该代码异常是相同的,但 class 引用是不同的,如 __CALayer、__NSArray、__NSSet 等,我什至不使用那些class直接。有帮助吗?
这里是观察者class初始化方法:
override init() {
super.init()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "downloadChapter:", name: "downloadListNotification", object: DisplayMangaViewController.self)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "downloadChapter:", name: "downloadListNotification", object: DownloadRequestListViewController.self)
}
还有我在里面的 post 通知 :
let userInfo = ["downloadList" : self.selectedChapters , "mangaName" : self.obtainedMangaName]
let notification = NSNotification(name: "downloadListNotification", object: DownloadRequestListViewController.self, userInfo: userInfo as [NSObject : AnyObject])
NSNotificationCenter.defaultCenter().postNotification(notification)
这是一个异常示例:
2015-09-05 19:49:45.598 TurkİşManga[12708:58814] -[__NSArrayM downloadChapter:]: unrecognized selector sent to instance 0x7fbf9c80dd90 2015-09-05 19:49:45.600 TurkİşManga[12708:58814] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM downloadChapter:]: unrecognized selector sent to instance 0x7fbf9c80dd90'
这里还有 downloadChapter 方法的草稿:
func downloadChapter(notification : NSNotification){}
显然我的观察者 class 被释放,因此当通知发布时,任何观察者都会被释放。所以在发布任何通知之前,从观察者 class 创建一个实例已经解决了这个问题。谢谢。