Call reloadData on a UITableView from a different controller

我的梦境 提交于 2019-12-12 05:01:51

问题


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.



来源:https://stackoverflow.com/questions/2050576/call-reloaddata-on-a-uitableview-from-a-different-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!