简体   繁体   English

Swift / tableView使用InstantiateViewControllerWithIdentifier传递数据

[英]Swift / tableView pass data with instantiateViewControllerWithIdentifier

I have an array of BackendlessUsers filled within a tableView. 我在tableView中填充了一个BackendlessUsers数组。 How can I pass the user within the didSelectRowAtIndexPath function? 如何在didSelectRowAtIndexPath函数中传递用户?

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. 非常感谢您的帮助。

Create a var user: DJProfileAsUserVC! 创建一个var用户:DJProfileAsUserVC! in DJProfileAsUserVC and after that to this: 在DJProfileAsUserVC中,然后执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM