我想在一個單獨的swift文件(Login.swift)上設置一個NSUserDefaults變量來確定我的用戶是否已登錄。如果用戶確實已登錄,LoginViewController將消失,並且HomeViewController將會所示。但是我正在拋出這個錯誤UIViewController實例問題
在類型'UIViewController'上使用實例成員'dismissViewControllerAnimated';你的意思是使用'UIViewController'類型的值嗎?
這是我的代碼
//success
else if value["username"] != nil && value["password"] == nil && value["message"] == nil
{
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn")
LoginViewController.dismissViewControllerAnimated(true, completion:nil)
if let api_key = value["api_token"].string
{
print("The token is " + api_key)
}
else
{
print("error parsing api token")
}
//pass data to Users class
_ = Users.init(Name: value["name"].string, Email: value["email"].string, Id: value["id"].int, ProfilePicture: value["profile_picture"].string, Username: value["username"].string)
}
dismissViewControllerAnimated是和對象方法,爲什麼你使用類名稱來調用它。 –