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
你可以向我詳細說明你的問題到底發生了什麼? –
這沒關係我已經設法解決它。感謝您試圖幫助:) – noobdev