I have looked at a number of other SO questions related to this question and have not found one dealing with my specific situation. I create a variable number of tableViews programmatically in one method. At a later point, I would like to reload the data in any one of the tableViews in another method. I would like to use...
[tableView reloadData];
to reload the data in a specific tableView. The problem I am having is accessing the tableView that was created programmatically at a later point. My thought is to set a unique tag for each tableView as it is created.
So here is my question. Is it possible to create and initialize a tableView by referring to an existing tableView's tag. For instance, with a UIView it is possible to...
UIView *notATableView = [[UIView alloc] viewWithTag:1];
which would allow me to modify the view whose tag was equal to 1. Does a similar possibility exist for tableViews?
Just refer to the UITableViews by their property names.
[self.thisTableView reloadData];
[self.thatTableView reloadData];
No tags needed!
You can also use the property names for IF checking in your UITableViewDataSource and UITableViewDelegate methods
if(tableView == self.thisTableView){
[tableView reloadData];
}
Yes, you can set the tag on your table view when you create it and retrieve the table view later using viewWithTag
.
// Assuming you've added the table view as a subview to the current view controller
UITableView *tableView = (UITableView *)[self.view viewWithTag:1];
However, you're not re-allocating it. You're just getting a pointer to it.
Then, just reload the data or do whatever:
[tableView reloadData];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With