我刚刚更新到Xcode 7.3。每当我点击按钮或文本字段时,视图中的所有对象都会消失。我不知道为什么会发生这种情况或者是什么引起的。 BTW:当我按下按钮时,我知道代码,因为我看到弹出的警报。 此外,当我点击“没有帐户”时,视图也不会消失。按钮。
The view when I tap on the login button or either text field
这是我的代码:
import UIKit
import Firebase
import Presentr
import SWMessages
class LoginViewController: UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: HideShowPasswordTextField!
@IBOutlet weak var loginButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(animated: Bool) {
if ((FIRAuth.auth()?.currentUser) != nil) {
} else {
self.performSegueWithIdentifier("loginSegue", sender: nil)
}
}
@IBAction func didPressLogin(sender: AnyObject) {
func show() {}
loginButton.selected = true
if emailField.text == "" {
delay(2, closure: { () -> () in
func showFail() {}
self.loginButton.selected = false
let title = "Oops!"
let body = "You didn't enter an email!"
let controller = Presentr.alertViewController(title: title, body: body)
let tryAgainAction = AlertAction(title: "Try again", style: .Cancel){}
controller.addAction(tryAgainAction)
let presenter = Presentr(presentationType: .Alert)
self.customPresentViewController(presenter, viewController: controller, animated: true, completion: nil) })
} else if passwordField.text == "" {
delay(2, closure: { () -> () in
func showFail() {}
self.loginButton.selected = false
let title = "Oops!"
let body = "You didn't enter a password!"
let controller = Presentr.alertViewController(title: title, body: body)
let tryAgainAction = AlertAction(title: "Try again", style: .Cancel){}
controller.addAction(tryAgainAction)
let presenter = Presentr(presentationType: .Alert)
self.customPresentViewController(presenter, viewController: controller, animated: true, completion: nil) })
} else {
FIRAuth.auth()?.signInWithEmail(emailField.text!, password: passwordField.text!, completion: { (user, error) -> Void in
if error == nil {
func showSuccess() {}
self.loginButton.selected = false
self.performSegueWithIdentifier("loginSegue", sender: nil)
} else {
func showFail() {}
self.loginButton.selected = false
SWMessage.sharedInstance.showNotificationInViewController ( self, title: "Oops!", subtitle: error?.localizedDescription, image: nil, type: .Error, duration: .Automatic, callback: nil, buttonTitle: "Try again", buttonCallback: {}, atPosition: .Top, canBeDismissedByUser: true )
}
})
}
}
@IBAction func noAccount(sender: UIButton) {
// TODO: Decide whether to allow users to create an account or not.
UIApplication.sharedApplication().openURL(NSURL(string: "http://kalissaac.github.io/SmaLert")!)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
// MARK: UITextFieldDelegate
extension LoginViewController: UITextFieldDelegate {
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, textField string: String) -> Bool {
return passwordField.textField(textField, shouldChangeCharactersInRange: range, replacementString: string)
}
func textFieldDidEndEditing(textField: UITextField) {
passwordField.textFieldDidEndEditing(textField)
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
if textField == emailField { // Switch focus to other text field
passwordField.becomeFirstResponder()
}
return true
}
}
// MARK: HideShowPasswordTextFieldDelegate
// Implementing this delegate is entirely optional.
// It's useful when you want to show the user that their password is valid.
extension LoginViewController: HideShowPasswordTextFieldDelegate {
func isValidPassword(password: String) -> Bool {
return password.characters.count > 6
}
}
答案 0 :(得分:0)
我通过删除自定义类并重新添加它来解决这个问题。这一定是个bug。感谢您帮助@binchik。