2016-01-13 49 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