gpt4 book ai didi

ios - 当点击按钮或文本字段时, View 中的对象会消失

转载 作者:行者123 更新时间:2023-11-30 13:14:08 24 4
gpt4 key购买 nike

我刚刚更新到 Xcode 7.3。每当我点击按钮或文本字段时, View 中的所有对象都会消失。我不知道为什么会发生这种情况或导致它的原因。
顺便说一句:我知道当我按下按钮时代码运行,因为我看到了弹出的警报。
此外,当我点击“没有帐户”按钮时, View 不会消失。

The view

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
}
}

最佳答案

我通过删除自定义类并重新添加它来解决这个问题。这一定是个bug。感谢您帮助@binchik。

关于ios - 当点击按钮或文本字段时, View 中的对象会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38422768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com