2015-08-18 124 views
0

我正在使用performSegueWithIdentifier并且所有这些设备都可以正常工作,但有一个根本不起作用。performSegueWithIdentifier注册后解析不起作用

我正在使用Parse.com来注册用户,并且我想在他们完成升级后执行一个segue,但是我无法使其工作。我认为performSegue应在功能是地方signUpViewController

enter image description here

我的代码:

import UIKit 
import Parse 
import ParseUI 
import Bolts 
import FBSDKCoreKit 
import FBSDKLoginKit 
import FBSDKShareKit 
import CoreLocation 

struct localizacaoActualizada { 

static var rua = "" 
static var localidade = "" 
static var codigopostal = "" 
static var giropostal = "" 
static var country = "" 


} 


class ViewController: UIViewController, ENSideMenuDelegate, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, CLLocationManagerDelegate { 



var logInViewController: PFLogInViewController! = PFLogInViewController() 
var signUpViewController: PFSignUpViewController! = PFSignUpViewController() 

var localidadeActual = "" 

@IBOutlet weak var userLogedIn: UILabel! 

let locationManager = CLLocationManager() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.sideMenuController()?.sideMenu?.delegate = self 

    self.locationManager.delegate = self 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest 
    self.locationManager.requestWhenInUseAuthorization() 
    self.locationManager.requestAlwaysAuthorization() 
    self.locationManager.startUpdatingLocation() 



    // Se ta loggado 
    var user = PFUser.currentUser() 


    if (user?.username != nil) { 



     // self.performSegueWithIdentifier("aposLogin", sender: self) 


    } 



} 


override func viewDidAppear(animated: Bool) { 
    super.viewDidAppear(true) 

    var user = PFUser.currentUser() 
    self.userLogedIn.text = user?.username 




    if (user?.username == nil) { 

     self.logInViewController.fields = (PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.PasswordForgotten | PFLogInFields.DismissButton) 

     //PFLogInFields.Facebook 




     var logInLogoTitle = UILabel() 
     logInLogoTitle.text = "ParaFora" 

     var SignUpLogoTitle = UILabel() 
     SignUpLogoTitle.text = "ParaFora" 

     //self.logInViewController.facebookPermissions = [ "friends_about_me" ] 
     self.logInViewController.logInView!.logo = logInLogoTitle 
     self.logInViewController.delegate = self 
     self.signUpViewController.signUpView!.logo = SignUpLogoTitle 
     self.signUpViewController.delegate = self 
     self.logInViewController.signUpController = self.signUpViewController 

    } 

    else { 

     //Tentativa 1 
     //self.locationManager.stopUpdatingLocation() 
     var user = PFUser.currentUser() 
     user?["localidade"] = localidadeActual 
     user?.saveInBackground() 



     //tentativa 2 

     //var user = PFUser.currentUser() 
     //var idUser = user?["objectId"] as! String 
     // println("O id do utilizador actual:" + idUser) 

     // var query = PFQuery(className:"User") 
     // query.getObjectInBackgroundWithId(idUser) { 
     //  (User: PFObject?, error: NSError?) -> Void in 
     //  if error != nil { 
     //   println(error) 
     //  } else if let User = User { 
     //   println("Tentativa de escrever" + self.localidadeActual + "no servidor") 
     //   User["localidade"] = self.localidadeActual 
     //   User.saveInBackground() 
    //   println("done?") 
    //  } 
     // } 
     // 



    // self.performSegueWithIdentifier("aposLogin", sender: self) 
    } 
} 

//Localizacao 

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) 
{ 

    CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: {(placemarks, error)->Void in 

     if (error != nil) 
     { 
      println("Error: " + error.localizedDescription) 
      return 
     } 

     if placemarks.count > 0 
     { 
      let pm = placemarks[0] as! CLPlacemark 
      self.displayLocationInfo(pm) 
     } 
     else 
     { 
      println("Error with the data.") 
     } 
    }) 
} 


func displayLocationInfo(placemark: CLPlacemark) 
{ 
    locationManager.stopUpdatingLocation() 
    //self.locationManager.stopUpdatingLocation() 
    println(placemark.locality) 
    println(placemark.postalCode) 
    println(placemark.administrativeArea) 
    println(placemark.country) 
    println(placemark.location) 
    println(placemark.administrativeArea) 
    println(placemark.subAdministrativeArea) 

//  println(placemark.addressDictionary) 
    //  println(placemark.areasOfInterest) 

    localidadeActual = placemark.locality 
    localizacaoActualizada.rua = placemark.name 
    localizacaoActualizada.localidade = placemark.locality 

    //Guarda o codigo postal na estrutura 
    if count(placemark.postalCode) > 4{ 
    localizacaoActualizada.codigopostal = placemark.postalCode.substringWithRange(Range<String.Index>(start: advance(placemark.postalCode.startIndex, 0), end: advance(placemark.postalCode.endIndex, -3))) 
    localizacaoActualizada.giropostal = placemark.postalCode.substringWithRange(Range<String.Index>(start: advance(placemark.postalCode.startIndex, 4), end: advance(placemark.postalCode.endIndex, 0))) 

    } 

    else { 
     localizacaoActualizada.codigopostal = placemark.postalCode 
    } 





    // Obtem a localidade no serv 


    var user = PFUser.currentUser() 
    println(user?["localidade"]) 
    //fim obter localidade 

} 

func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) 
{ 
    println("Error: " + error.localizedDescription) 
} 

//fim local 


// MARK: Parse Login 

func logInViewController(logInController: PFLogInViewController, shouldBeginLogInWithUsername username: String, password: String) -> Bool { 


    if (!username.isEmpty || !password.isEmpty) { 
     return true 
    }else { 
     return false 
    } 

} 



func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) { 

    self.dismissViewControllerAnimated(true, completion: nil) 

    self.performSegueWithIdentifier("aposLogin", sender: self) 


} 

func logInViewController(logInController: PFLogInViewController, didFailToLogInWithError error: NSError?) { 
    println("Failed to login...") 
} 

func logInViewControllerDidCancelLogIn(logInController: PFLogInViewController) { 

} 

// MARK: Parse Signup 

func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) { 


    self.dismissViewControllerAnimated(true, completion: nil) 

    self.performSegueWithIdentifier("setupCliente", sender:self) 


} 
func signUpViewController(signUpController: PFSignUpViewController, didFailToSignUpWithError error: NSError?) { 

    println("FAiled to sign up...") 

} 



func signUpViewControllerDidCancelSignUp(signUpController: PFSignUpViewController) { 

    println("User dismissed sign up.") 

} 

// MARK: Actions 

@IBAction func simpleAction(sender: AnyObject) { 

    self.presentViewController(self.logInViewController, animated: true, completion: nil) 

} 



@IBAction func logoutAction(sender: AnyObject) { 

    PFUser.logOut() 

} 



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


@IBAction func toggleSideMenu(sender: AnyObject) { 
    toggleSideMenuView() 
} 

// MARK: - ENSideMenu Delegate 
func sideMenuWillOpen() { 
    println("sideMenuWillOpen") 
} 

func sideMenuWillClose() { 
    println("sideMenuWillClose") 
} 

func sideMenuShouldOpenSideMenu() -> Bool { 
    println("sideMenuShouldOpenSideMenu") 
    return true 
} 
} 
+0

你检查了signUpViewController-方法被调用? – Christian

+0

是的,因为它关闭了viewcontroller并且我使用调试器进行了检查。 –

回答

0

在你signUpViewController功能你解雇当前视图控制器,然后你与发件人为调用performSegueWithIdentifier你刚刚解雇的视图控制器。尝试删除dismissViewControllerAnimated方法调用

+0

已经尝试过,没有成功。我有类似的工作:'logInViewController'。但注册它不工作= / –

0

我有同样的问题。但我设法解决它,但它不是一个完美的解决方案。我所做的就是解雇PFSignUpViewController

但在此之前,我设置了一个全局变量,在我的情况下称为initialSignUp的布尔为true。一旦控制器被解雇,我检查了PFLogInViewControllerviewDidAppear()方法,如果initialSignUp为真。 如果是这种情况,我将它改回false,然后执行segue。

此替代方法适用于我,我希望我可以帮助您解决您的问题。

0

我认为你需要设置loginViewController的signupViewController的委托。像这样的东西(抱歉,它在迅速,但你可以propably工作了):

let loginViewController = LoginViewController() 
loginViewController.delegate = self 
loginViewController.signUpController?.delegate = self 

,然后,你可以调用下面的方法来关闭该视图和执行赛格瑞(或其他任何东西)。

func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) { 
    self.dismissViewControllerAnimated(true, completion: nil) 
    self.performSegueWithIdentifier("segueID") 

} 
func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) -> Void { 
    self.dismissViewControllerAnimated(true, completion: nil) 
    self.performSegueWithIdentifier("segueID") 
} 

希望得到这个帮助。它为我工作。

干杯, 朱利安