Call reloadData on a UITableView from a different

2019-08-31 16:00发布

问题:

I have a table view that uses a location manager to grab the users location. In my didUpdateToLocation method, i create an NSURLConnection to go off to my webservice which returns JSON.

The delegate of the Connection is set to an instance of my JSONController class and in its connectionDidFinishLoading method, i need to call [tableView reloadData] to get the table view to refresh.

How do i get a reference to my table view? I tried:

TableViewController *myTVC = [[TableViewController alloc] init];
[myTVC.tableView reloadData];

but it did not work.

What do i need to do?

Thanks.

回答1:

If I understand you flow, you need to set a delegate for your JSONController to call back to your Controller that is controlling your TableView. Somehow you need to get a pointer back to your TableView, and exposing that as a accessor from you ViewControler could break encapsulation so it would be better to just have a delegate that you set so you could post to the delegate.