Fred J.
Fred J.

Reputation: 6049

Swift 2.1 tableView cells layout and content to change in runtime

I need a tableView which could have any number of cells with different layout and/or data in different cells and could change in run time.

With static cells, I am limited by its initial layout creation and number of cells.

With prototype. I am limited by its fixed layout even though its number and data can change.

I need to select different layout as well as data and number of cells in runtime. How do I get this behaviour?

Thanks

Upvotes: 0

Views: 236

Answers (1)

Christopher Kevin Howell
Christopher Kevin Howell

Reputation: 1505

Use tableView:numberOfRowsInSection to dynamically change the number of cells in the UITableView depending on some model you have.

Use tableView:cellForRowAtIndexPath: to dynamically select one of your UITableViewCell subclasses, which will have a layout that you define, and populate it with data.

When your model changes, you can reload the cells in the tableView and they will change according to the logic in your UITableViewDataSource methods.

Upvotes: 1

Related Questions