我在尝试重新加载时遇到问题UITableView
从 XML 源加载的单元格数据。
这是场景。应用程序包含选项卡,其中一个选项卡中有一个表格视图,它从 XML 文件获取数据并且工作正常,但问题是当我想要更改提要类别并从另一个选项卡更改 XML 时,我可以刷新当前表格视图。
为了在我使用的选项卡之间切换
self.tabBarController.selectedIndex = 1;
并将类别提要传递到我想要加载的其他选项卡
xmlParser = [[XMLParser alloc] loadXMLByURL:categories];
并且它仍然加载相同的旧提要,而不是已传递的新提要。我检查过NSLog
进给值正常传递,但切换后就无法加载。
我也尝试过[self.tableView reloadData];
从当前选项卡和类别选项卡,它也不起作用。
您可以使用 NSNotifications 从其他选项卡发送通知,并在表视图中设置一个观察者来响应该通知。
Example
(调用表格视图重新加载的选项卡)每当您想要重新加载数据时,都放置此代码,因此当按下按钮或下载完成等时。
NSNotification * notification = [NSNotification notificationWithName:@"updateTable" object:nil];
[[NSNotificationCenter defaultCenter] postNotification:notification];
在 UITableViewController / 具有 UITableView 的类中,执行以下操作。
在你的 viewDidLoad 添加:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTableView) name:@"backtolist" object:nil];
然后添加函数updateTableView
- (void) updateTableView: (NSNotification*) note
{
//Do whatever needs to be done to load new data before reloading the tableview
[_tableView reloadData];
}
希望这可以帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)