我目前正在为注册屏幕实现一些代码(使用快速清洁的体系结构)-当按下注册按钮并且出现错误时,我将触发一些功能。我将粘贴以下代码以获取帮助:
import UIKit
protocol SignupFormErrorLogic {
func showValidationError(_ message: String)
}
class SignupViewController: UIViewController, SignupFormErrorLogic {
var interactor: SignupBusinessLogic?
var router: (NSObjectProtocol & SignupRoutingLogic)?
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
private func setup() {
let viewController = self
let interactor = SignupInteractor()
let router = SignupRouter()
viewController.interactor = interactor
viewController.router = router
interactor.router = router
interactor.viewController = viewController
router.viewController = viewController
}
@IBOutlet var fullNameTextField: UITextField!
@IBOutlet var emailTextField: UITextField!
@IBOutlet var passwordTextField: UITextField!
@IBAction func cancelButtonPressed(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
@IBAction func signupButtonPressed(_ sender: Any) {
let request = Signup.Request(
name: fullNameTextField.text!,
email: emailTextField.text!,
password: passwordTextField.text!
)
interactor?.createAccount(request: request)
}
func showValidationError(_ message: String) {
let alertCtrl = UIAlertController(title: "Oops! An error occurred", message: message, preferredStyle: .alert)
alertCtrl.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
self.show(alertCtrl, sender: self)
}
}
当我运行模拟器时,输入要创建的帐户的详细信息,然后单击“注册”,它会触发我的错误请求,但我不知道问题出在哪里。我应该使用do / try / catch块找出问题吗?如果可以,我应该在哪里/如何使用它?
谢谢