2016-07-26 45 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