【发布时间】:2016-05-13 05:46:00
【问题描述】:
我正在尝试在单独的 swift 文件 (Login.swift) 上设置 NSUserDefaults 变量以确定我的用户是否已登录。如果用户确实已登录,则 LoginViewController 将消失,而 HomeViewController 将显示。但是我被抛出了这个错误
在“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 是和对象方法,为什么你用类名来调用它..?
标签: ios uiviewcontroller swift2