2015-04-12 178 views
1

我使用的XCode 6performSegueWithIdentifier导致崩溃

框架PARSE设立注册/登录页面当我尝试执行赛格瑞(其拼写correcty),悬停,该应用程序崩溃,即使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)    
     }  
    } 
} 

的赛格瑞是viewWillAppear方法内。 PFUser().currentUser()存储有关当前登录用户的信息,所以它是nil如果没有用户登录。

你能找出它为什么崩溃吗? 我试图把viewDidLoad内的segue,但没有别的,它甚至没有坠毁。

+0

请发布错误。 – Schemetrical

+0

我只在AppDelegate.swift @Schemetrical – dpstart

+0

上得到SIGABRT是的,但是SIGABRT说什么?你是不是误解了故事板上的某些内容? – Schemetrical

回答

0

尝试在viewDidAppear中搜索:并检查您的segue标识符是否与故事板上的segue相匹配。

+0

我已经在那里逗留了。是的,标识符匹配。 – dpstart