![](/img/trans.png)
[英]NSInvalidArgumentException when updating WebView from AppDelegate
[英]NSInvalidArgumentException when sending local notification from AppDelegate
当用户在后台运行时,当用户点击收到的通知时,我想打开特定的视图。 我从这样的appDelegate发布通知:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
if let info = notification.userInfo {
// Check if value present before using it
if let s = info["CallIn"] {
if(s as! String == "10minBeforeMeeting"){
NSNotificationCenter.defaultCenter().postNotificationName("EventListShouldRefresh", object: self)
}
if(s as! String == "CallInNotification"){
if let UUID = info["UUID"]{
print("ha: \(UUID)")
NSNotificationCenter.defaultCenter().postNotificationName("OpenDetailViewOfMeeting", object: self, userInfo: ["UUID":UUID])
}
}
}
else {
print("no value for key\n")
}
}
else {
print("wrong userInfo type")
}
}
在课堂上,我是该通知的观察者:
//in viewDidLoad:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "openDetailView", name: "OpenDetailViewOfMeeting", object: nil)
func openDetailView(notification: NSNotification) {
let userInfo = notification.userInfo as! [String: AnyObject]
let UUIDunbind = userInfo["UUID"] as! String
let events = CalendarController.sharedInstance.todaysMeetings()
for event in events {
if(event.UUID == UUIDunbind){
let detailViewController = DetailViewController()
detailViewController.meeting = event
self.mainViewController.showDetailViewController(detailViewController, sender: self)
}
}
}
当我收到通知时,我得到了NSInvalidArgumentException:似乎它甚至不在方法openDetailView中。 在其他地方,我使用的是完全相同的结构,并且可以正常工作(尽管通知不是从appDelegate发布的,而是直接从某个类发布的)。 错误日志:
** *由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[CallIn.ViewController openDetailView]:无法识别的选择器已发送到实例0x7f9623c4d330”
我究竟做错了什么?
您的选择器结构缺少一个:
,它表示openDetailView
方法的参数notification
。
NSNotificationCenter.defaultCenter().addObserver(self, selector: "openDetailView:", name: "OpenDetailViewOfMeeting", object: nil)
如果您需要更多信息,可以在此处找到文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.