2016-01-13 46 views
0

我想在用户点击接收到的通知时,在应用程序处于后台时打开特定的视图。我从的appDelegate发布的通知是这样的:当从AppDelegate发送本地通知时发生NSInvalidArgumentException

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'

我在做什么错?

+0

:在选择器方法中缺少像 - selector:“openDetailView:” – Sujit

回答

0

您在选择器结构中缺少:,它表示您的openDetailView方法中的参数notification

NSNotificationCenter.defaultCenter().addObserver(self, selector: "openDetailView:", name: "OpenDetailViewOfMeeting", object: nil) 

如果你需要更多的信息,你可以找到文档here