I have been trying to pass data from Viewcontroller to UITableView custom cell using custom delegate.There are answers for passing data from Custom cell to ViewController but none for the viceversa .Can anyone suggest me with some idea or sample code.
Asked
Active
Viewed 292 times
-1
-
can you show ur tried code – Anbu.Karthik Sep 29 '16 at 09:28
-
You cant pass directly. But you can do by using model class. Model class contains the data what you are going to pass. In `viewcontroller` you can save the data to Model. And in customcell class you can retrive. – Dhanunjaya Sep 29 '16 at 09:44
-
why downvote the question? – Deepak Karthik Sep 29 '16 at 09:49
-
what do u mean by model class.Are you refering to sharedclass? @user3774439 – Deepak Karthik Sep 29 '16 at 09:56
-
Yeah. You can use that – Dhanunjaya Sep 29 '16 at 11:10
1 Answers
0
I am not sure if this is what you mean, but you can set the data in function tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
For example:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: ViewController.cellIdentifier, for: indexPath) as! CustomCell
cell.data = data
return cell
}

Carien van Zyl
- 2,853
- 22
- 30