从其他控制器调用UITableView上的reloadData [英] Call reloadData on a UITableView from a different controller

查看:72
本文介绍了从其他控制器调用UITableView上的reloadData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,该表视图使用位置管理器来获取用户的位置.在我的 didUpdateToLocation 方法中,创建一个 NSURLConnection 转到返回JSON的Web服务.

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.

Connection的委托设置为我的JSONController类的实例,并在其 connectionDidFinishLoading 方法中,我需要调用 [tableView reloadData] 以获得表视图刷新.

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];

但是没有用.

我需要做什么?

谢谢.

推荐答案

如果我理解您的流程,则需要为JSONController设置一个委托,以回调到控制TableView的Controller.不知何故,您需要获得一个指向TableView的指针,并将其作为ViewControler的访问器公开,可能会破坏封装,因此最好设置一个委托以便将其发布到委托中.

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.

这篇关于从其他控制器调用UITableView上的reloadData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆