My tableview does not reload data even though I call tableview.reloaddata(). I am taking user input for cells through a custom alert view
Tableview not reloading
Add a Comment
My tableview does not reload data even though I call tableview.reloaddata(). I am taking user input for cells through a custom alert view
Please show enough code to reprocude the issue.
Maybe you are calling `reload()` in non-main thread, or you may be calling `reload()` for another table view, or ...
When you get the input from user, do you update the datasource (the array that should contain all the data needed to fill the cells) ?
You have to use this datasource array in
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
So, please show:
- the alert where user enters data
- the tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) func
As OOPer pointed, if you call reloadData from inside the alert, need to first dispatch to the main thread.
Here's what they are writing about:
[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:
^(UIAlertAction * action) {
dispatch_async(dispatch_get_main_queue(), ^{ //need to encase your commands in thi
[myTableView reloadData]; // (your commands here)
}); // and this
}];
Sure.
And if Swift:
let okAction = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
// UPDATE data
DispatchQueue.main.async {
self.tableView.reloadData()
}
})