1

I have an array of BackendlessUsers filled within a tableView. How can I pass the user within the didSelectRowAtIndexPath function?

var deejays: [BackendlessUser] = []

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    print("You selected cell #\(indexPath.row)!")
    self.tableView.deselectRowAtIndexPath(indexPath, animated: true)

    **let user = deejays[indexPath.row]**
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("DJProfileAsUserVC") as! DJProfileAsUserVC

    dispatch_async(dispatch_get_main_queue()) {
        self.presentViewController(vc, animated: true, completion: nil)
    }
}

Help is very appreciated.

David Seek
  • 16,783
  • 19
  • 105
  • 136

1 Answers1

2

Create a var user: DJProfileAsUserVC! in DJProfileAsUserVC and after that to this:

let user = deejays[indexPath.row]
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("DJProfileAsUserVC") as! DJProfileAsUserVC
vc.user = user
vbgd
  • 1,937
  • 1
  • 13
  • 18