2016-09-29 72 views
-1

我一直在试图从视图控制器传递数据使用自定义delegate.There是从自定义单元格的数据传递到视图控制器的答案UITableView的自定义单元格,但没有对反之亦然。可有人建议我有一些想法或示例代码。如何从视图控制器设置数据UITableView的自定义单元格

+0

可以显示乌尔试图代码 –

+0

你不能直接传递。但是你可以通过使用模型类来完成。模型类包含您要传递的数据。在'viewcontroller'中,你可以将数据保存到Model中。在customcell类中,您可以回顾。 – Dhanunjaya

+0

为什么downvote这个问题? –

回答

0

我不知道,如果这是你的意思,但你可以在function tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

设置数据例如:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: ViewController.cellIdentifier, for: indexPath) as! CustomCell 
     cell.data = data 
     return cell 

    } 
相关问题