2016-05-13 45 views
0

我有一個NSNotification函數調用時給我一個錯誤。我怎樣才能解決這個問題?NSNotification函數不能調用

這是一個被拋出的錯誤:

無法將類型「(NSNotification)。鍵入」(又名「NSNotification,類型」)的值,可以預期的參數類型「NSNotification」

受影響的代碼塊:

@IBAction func loginBtn(sender: AnyObject) { 

    let loginobj = Login(userName : self.usernameField.text!, passWord : self.pwdField.text!) 
    loginobj.getRequest() 
    handlingAuthentication(NSNotification) 

} 

這是被調用的函數

func handlingAuthentication(notification: NSNotification) { 

    let errorDectected = notification.object as! Bool 

    if(errorDectected){ 
     //initialize Alert Controller 
     let alertController = UIAlertController(title: "Authentication error", message: AuthHelpers.sharedInstance.errorMessage, preferredStyle: .Alert) 

     //Initialize Actions 
     let okAction = UIAlertAction(title: "Ok", style: .Default){ 
       (action) -> Void in 
       self.dismissViewControllerAnimated(true, completion: nil) 
      } 

     //Add Actions 
     alertController.addAction(okAction) 

     //Present Alert Controller 
     self.presentViewController(alertController, animated: true, completion: nil) 

    } 
    else 
    { 
     print("error not found") 
     NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn") 

     NSUserDefaults.standardUserDefaults().synchronize() 

     self.dismissViewControllerAnimated(true, completion:nil) 

    } 

} 

代碼,其中NSNotification被初始化:

var error = "true" 
NSNotificationCenter.defaultCenter().postNotificationName("errorFound", object:error) 

我不知道這是否是正確的,但我想改變錯誤的價值,我只想做error = false

的屏幕截圖引發錯誤: Error thrown

+0

你可以向我詳細說明你的問題到底發生了什麼? –

+0

這沒關係我已經設法解決它。感謝您試圖幫助:) – noobdev

回答

0

原來我只是不得不添加

NSNotificationCenter.defaultCenter().postNotificationName("errorPresent", object:errorDict) 

我在Login.swift功能getRequest()底部張貼在我LoginViewController代碼的通知和

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.handlingAuthentication(_:)), name:"errorPresent", object: nil) 

接收通知以及

func handlingAuthentication(notification: NSNotification) { 

    let dict = notification.object as! NSDictionary 
} 

處理通過的數據