gpt4 book ai didi

swift - performSegueWithIdentifier 导致崩溃

转载 作者:行者123 更新时间:2023-11-28 09:09:49 26 4
gpt4 key购买 nike

我正在 XCode 6 上使用框架 PARSE 设置注册/登录页面。

当我尝试执行一个 segue(它拼写正确)时,悬停,应用程序崩溃,即使 segue 在 if 语句中也是如此。

代码如下:

import UIKit
import Parse

class ViewController: UIViewController, UINavigationControllerDelegate{

var signUpMode = false

func displayAlert(title:String, message:String){
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}

//Outlet and actions

@IBOutlet var username: customTextField!
@IBOutlet var email: customTextField!
@IBOutlet var password: customTextField!

//Need the outlets for changes betweeen signUp and logIn modes!!!


@IBAction func signUp(sender: AnyObject) {

if signUpMode == true {

var user = PFUser()
user.username = username.text
user.password = password.text
user.email = email.text

// other fields can be set just like with PFObject
//user["phone"] = "415-392-0202"

user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if error == nil {
// Hooray! Let them use the app now.
} else {
println("error")
self.displayAlert("Username already in use", message: "Please use another username")
}
}
}
else {

PFUser.logInWithUsernameInBackground(email.text, password:password.text) {
(user: PFUser!, error: NSError!) -> Void in

if user != nil {
self.displayAlert("You're in", message: "And you'll be successful")
self.performSegueWithIdentifier("goToPost", sender: self)
} else {
self.displayAlert("Wrong username or password", message: "Please try again")
}
}
}


override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


override func viewWillAppear(animated: Bool) {

if signUpMode == false {
self.username.hidden = true
self.email.placeholder = "username"
}
}

override func viewDidAppear(animated: Bool) {

if PFUser.currentUser() != nil {
performSegueWithIdentifier("goToPost", sender: self)
}
}
}

segue 在 viewWillAppear 方法中。PFUser().currentUser() 存储有关当前登录用户的信息,因此如果没有用户登录,则为 nil

你能找出它崩溃的原因吗?我试图将 segue 放在 viewDidLoad 中,但没有别的,它甚至没有崩溃。

最佳答案

尝试在 viewDidAppear: 中进行 segueing:并检查您的 segue 标识符是否与 Storyboard上的标识符匹配。

关于swift - performSegueWithIdentifier 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29595371/

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