从另一个选项卡重新加载UITableView [英] Reload UITableView from another tab

查看:154
本文介绍了从另一个选项卡重新加载UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法尝试重新加载从XML源加载的 UITableView 单元格数据。

I am having trouble trying to reload UITableView cell data which are being loaded from an XML source.

这是场景。应用程序包含选项卡,其中一个有一个tableview,它从XML文件中获取数据并且工作正常,但事情就是当我想要更改提要类别并从另一个选项卡更改XML时我可以刷新当前的tableview 。
为了在标签之间切换,我使用

Here is the scenario. App contains tabs, in one of them there is a tableview which gets it's data from an XML file and works just ok, but the thing is when I want to change the feed category and change the XML from another tab I can refresh the current tableview. For switching between tabs I use

self.tabBarController.selectedIndex = 1;

并将类别Feed传递给我要加载的其他标签

and pass the category feed to the other tab which I want to load

xmlParser = [[XMLParser alloc] loadXMLByURL:categories];

它仍会加载相同的旧Feed,而不是已经传递的新Feed。我检查了 NSLog 并且Feed值正确传递,但切换后它才会加载。

and it still loads the same old feed, not the new one which has been passed. I checked with NSLog and the feed value passes properly but it just wont load after switching.

我也尝试过当前选项卡和类别选项卡中的 [self.tableView reloadData]; ,它也不起作用。

I also tried to [self.tableView reloadData]; from both current tab and the category tab and it didn't work either.

推荐答案

您可以使用NSNotifications从其他选项卡发送通知,并在您的tableview中使用oberver响应该通知。

You can use NSNotifications to send a notification from your other tab and have a oberver in your tableview that responds to that notification.

示例

(调用tableview的重新加载的Tab)在您想要重新加载数据时放置此代码,因此当按下按钮或下载完成时等等。

(Tab calling the reload of the tableview) put this code whenever you want to reload the data, so when a button is pushed or a download is finished etc.

NSNotification * notification = [NSNotification notificationWithName:@"updateTable" object:nil];
[[NSNotificationCenter defaultCenter] postNotification:notification];

在UITableViewController /具有UITableView的类中,执行以下操作。

In the UITableViewController / the class with the UITableView, do the following.

在viewDidLoad中添加:

in your viewDidLoad add:

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(updateTableView) name:@"backtolist" object:nil];

然后添加函数updateTableView

Then add the function updateTableView

- (void) updateTableView: (NSNotification*) note
{
    //Do whatever needs to be done to load new data before reloading the tableview
    [_tableView reloadData];
}

希望这会有所帮助

这篇关于从另一个选项卡重新加载UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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