jeudi 25 juin 2015

Queue of functions - Swift

I have a table in which each cell there is the profile name of a user. I want that when the profile name is clicked, it will go to the profile page of the user. I created a delegate from the cell for this. But the problem is, the variable "goToProfileVar" is empty at the starting point. Then I assign a value to it with the "goToCell103" function. Then the assigned value should be user in the "prepareforsegue" to pass the username data. The problem is that, prepareforseque functions works first and the "goToProfileVar" becomes empty, then the variable is assign to the cell.username.text.

How can I queue these functions?

 var goToProfileVar = String()
 var goToProfileVar2 = String()

func goToCell103(cell: mainCell)
{
    var goToCell103:mainCell? = cell as mainCell
    var indexPath: NSIndexPath  = self.resultsTable.indexPathForCell(goToCell103!)!

    goToProfileVar = cell.usernameLbl.text!
    goToProfileVar2 = cell.objectid.text!
           println("\(goToProfileVar) followers liked this.")
    println("\(goToProfileVar2) followers liked this.")



}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {



    if (segue.identifier == "goToProfile8") {
        var svc = segue.destinationViewController as! generalProfileLast;
        svc.dataPassed = goToProfileVar}

   else if (segue.identifier == "goToLikers1") {
        var svc = segue.destinationViewController as! likers;
        svc.dataPassed = goToProfileVar2}

    else if (segue.identifier == "goToComments1") {
        var svc = segue.destinationViewController as! enterCommentVC;
        svc.dataPassed = goToProfileVar2}

    else if (segue.identifier == "goToComments2") {
        var svc = segue.destinationViewController as! commenters;
        svc.dataPassed = goToProfileVar2}

      println("\(goToProfileVar) followers liked this very.")
     println("\(goToProfileVar2) followers liked this very.")

}

See more ..

Aucun commentaire:

Enregistrer un commentaire