所以我正在练习iOs编程,我似乎无法找到解决问题的方法。我有一个“loginViewController”,我希望我的UIButton“Creer un compte”以模态方式呈现我的“注册”视图控制器。这是问题,当我启动模拟器并单击按钮时,它崩溃并将我带到AppDelegate的第一行,
“AppDelegate类:UIResponder,UIApplicationDelegate,Thread1信号SIGABRT。”
我通过控制将我的UIButton拖到Register视图控制器来完成segue。
以下是代码:
import UIKit
类LoginViewController:UIViewController {
@IBOutlet weak var LoginScreenImage: UIImageView!
@IBOutlet weak var codeTextField: UITextField!
@IBOutlet weak var nipTextField: UITextField!
@IBAction func showRegisterPage(sender: AnyObject) {
let registerViewController = self.storyboard?.instantiateViewControllerWithIdentifier("RegisterViewController") as RegisterViewController
self.showViewController(registerViewController, sender: self)
}
let client = Client.sharedInstance
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
LoginScreenImage.image = UIImage(named: "UQAMLOGO")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func connect() {
let code = codeTextField.text
let nip = nipTextField.text
if code != nil && nip != nil {
client.login(code, password: nip, callback: { (response) in
if let response = response {
if response.status == LoginStatus.Ok {
// Good login.
let homeViewController = self.storyboard!.instantiateViewControllerWithIdentifier("HomeViewController") as HomeViewController
self.showViewController(homeViewController, sender: self)
}
} else {
// Error
}
})
}
}
}
和RegisterViewController:
import UIKit
类RegisterViewController:UIViewController {
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
let client = Client.sharedInstance
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func register() {
let firstName = firstNameTextField.text
let lastName = lastNameTextField.text
let email = emailTextField.text
let password = passwordTextField.text
if(firstName != nil && lastName != nil && email != nil && password != nil){
client.register(email, password: password, firstName: firstName, lastName: lastName, callback: {(response) in
if let response = response{
if response.status == RegisterStatus.Ok{
let loginViewController = self.storyboard!.instantiateViewControllerWithIdentifier("LoginViewController") as LoginViewController
self.showViewController(loginViewController, sender: self)
}
}else{
//erreur
}
})
}
}
}
我尝试以编程方式执行此操作,尝试将viewControllers重置为其默认类(UIViewController)。
感谢大家的帮助,
查尔斯
答案 0 :(得分:0)
当你从一个按钮到另一个控制器的segue时,执行segue而不需要任何代码 - 你应该删除showRegisterPage方法。我不确定这是否是您唯一的问题,但您应该删除该方法,看看是否仍然出现错误。