【发布时间】:2015-12-18 18:25:36
【问题描述】:
我对 performSegueWithIdentifier 方法的实现不是启动 segue。
我尝试过在方法前后放置打印语句进行调试:它在之前打印,但在之后不打印,这显然表明该方法不起作用,对吧?
class ViewController: UIViewController{
var signupActive = true
@IBOutlet weak var username: UITextField!
@IBOutlet weak var password: UITextField!
var errorMessage = "Please try again later"
func displayAlert(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction((UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
})))
self.presentViewController(alert, animated: true, completion: nil)
}
@IBAction func signUp(sender: AnyObject) {
if username.text == "" || password.text == "" {
displayAlert("Error in form", message: "Please enter a username and password")
} else {
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
var errorMessage = "Please try again later"
if signupActive == true {
var user = PFUser()
user.username = username.text
user.password = password.text
user.signUpInBackgroundWithBlock({ (success, error) -> Void in
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if error == nil {
// Right here and below as well
self.performSegueWithIdentifier("login", sender: self)
} else {
if let errorString = error!.userInfo["error"] as? String {
errorMessage = errorString
}
self.displayAlert("Failed signup", message: errorMessage)
}
})
} else {
PFUser.logInWithUsernameInBackground(username.text!, password: password.text!, block: { (user, error) -> Void in
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if user != nil {
// Here too
print("kay")
self.performSegueWithIdentifier("login", sender: self)
print("yay")
} else {
if let errorString = error!.userInfo["error"] as? String {
errorMessage = errorString
}
self.displayAlert("Failed login", message: errorMessage)
}
})
}
}
}
【问题讨论】:
-
在 Xcode 中运行程序的调试版本并观察调试控制台。我的猜测是该调用引发了导致您的函数终止的异常。
-
@DuncanC 你是怎么做到的?这就是我一直在寻找的
-
从视图菜单中,选择“调试区域>激活控制台”。然后在项目窗口的右下角查看 2 个小蓝色框。确保它们都是蓝色的,并将调试控制台的两个部分之间的分隔线移动到两个部分之间的一半左右。然后运行您的程序并触发相关代码。
标签: ios swift segue uistoryboard uistoryboardsegue