2016-07-26 86 views
1

我有一個數組的BackendlessUsers填充在tableView中。我如何在didSelectRowAtIndexPath函數中傳遞用戶?Swift/tableView傳遞數據與instantiateViewControllerWithIdentifier

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) 
    } 
} 

幫助非常感謝。

回答

2

創建一個var用戶:DJProfileAsUserVC!在DJProfileAsUserVC和之後對此:

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

@property in swift? :/ –

+0

對不起,我會編輯。 – vladiulianbogdan

+0

完成。讓我知道如果這是你想要的。 – vladiulianbogdan