iOS界面回到主页刷新列表

    在好多APP中,首页中心是几个列表,然而每次从其他界面回到主页,都最好自动刷新一下列表,那么问题来了,如何自动刷新呢?一,可以在ViewWillAppear中调用刷新数据方法;二,用Block或者代理方法调用刷新数据;三,添加通知。

    如我的APP是抽屉式框架,中心页是三四个列表。我用的是通知方法。当然这种方法同样适用其他框架,如常用的标签式框架等。

    举例说明:A界面点击按钮后,通知B界面去请求网络,刷新B页面的内容 。

    解决方案:

1.在B界面创建的时候,如ViewDidLoad里,添加通知:

//回到首页刷新界面通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateIndex:) name:@"updateTransferIndex" object:nil];

2.在B界面添加通知调用刷新数据方法:

//MARK:收到通知刷新首页
- (void)updateIndex:(NSNotification *)notification
{
    [self loadRequest];
    [self.robbingTable loadRequest:shaixuanMark:(double)self.location.coordinate.latitude:(double)self.location.coordinate.longitude];
    [self.robbingTable.mainTableView reloadData];
    [self.sendingTable loadRequest:(double)self.location.coordinate.latitude:(double)self.location.coordinate.longitude];
    [self.sendingTable.mainTableView reloadData];
    [self.abnormalTable loadRequest:(double)self.location.coordinate.latitude:(double)self.location.coordinate.longitude];
    [self.abnormalTable.mainTableView reloadData];
}

3.在A界面按钮点击事件里,post通知:

//发送刷新通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"updateTransferIndex" object:self userInfo:nil];
    当然,这种添加通知以及Block方法都会耗费系统性能,但需要刷新的地方并不是很多,所以总体来说,这是比较实用并且容易理解的方法。如果大家有更好的办法,请多交流。

猜你喜欢

转载自blog.csdn.net/zhonglv_honeymoon/article/details/79743552