Reputation: 6077
I have a static UITableView
with n columns and 1 section. The cells are detailed with some dynamic content passed from another UIViewController
.
My solution is the following: I make a call in viewDidAppear
to present the dynamic content and eventually reload the view:
override func viewDidAppear(_ animated: Bool) {
setupDetails()
}
fileprivate func setupDetails() {
tableView.cellForRow(at: [0,0] as IndexPath)?.detailTextLabel?.text = "..."
tableView.cellForRow(at: [0,1] as IndexPath)?.detailTextLabel?.text = "..."
// .... multiple cells
tableView.reloadData()
}
The thing I don't like is that the content is updated after the view is shown to the user (thanks to the viewDidAppear
call).
For what concerns working on the cellForRow()
method, I could not have it working given the fact that the cell is statically created in my Storyboard.
My question is if there exists a pattern to be used in this specific case which I didn't think of. I basically want the view to be loaded before the view is presented, as if I was working with dynamic cells.
Upvotes: 0
Views: 640
Reputation: 16327
Don't use ViewDidAppear if you don't want you change to show to the user. Use ViewWillAppear and the view will already be in its final state when the user first sees it.
Upvotes: 1
Reputation: 534925
My question is if there exists a pattern to be used in this specific case
Yes. Don't use a static table. Your table is not static! "Static" means "never changes". Your table is the opposite of static; it does change. It is dynamic!
So, use an ordinary dynamic table. Maintain a data model that is consulted by the Three Big Questions (the data source methods). To update the table with new data, first update the data model, and then call reloadData
. That will cause cellForRowAt
to be called for you, and you'll populate each cell from the data model. That is much more efficient than what you're doing.
As for the flash, that's just a matter of timing; use viewWillAppear
instead of viewDidAppear
.
Upvotes: 1