我已经按照错误的建议尝试了“!= nil”。但这也不起作用。
下面是我的 TableViewController 中的代码
func viewDidAppear(animated: Bool) {
if (!PFUser.currentUser()) {
var loginAlert:UIAlertController = UIAlertController(title: "Sign Up / Log In", message: "Please Sign Up or Log In", preferredStyle: UIAlertControllerStyle.Alert)
loginAlert.addTextFieldWithConfigurationHandler({
textfield in
textfield.placeholder = "Username"
})
loginAlert.addTextFieldWithConfigurationHandler({
textfield in
textfield.placeholder = "Password"
textfield.secureTextEntry = true
})
loginAlert.addAction(UIAlertAction(title: "Log In", style: UIAlertActionStyle.Default, handler: {
alertAction in
let textFields:NSArray = loginAlert.textFields as NSArray
let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
PFUser.logInWithUsernameInBackground(usernameTextfield.text, password: passwordTextfield.text){
(user:PFUser!, error:NSError!)-> Void in
}
}))
}
}