您的位置:首页 > 移动开发 > IOS开发

iOS popViewControllerAnimated后刷新原先的表格

2015-08-12 10:12 561 查看
当主页面列表push子页面,子页面修改后pop回主页面后应该刷新主页面列表数据,不修改子页面信息就不刷新主页面列表,这里介绍个取巧的方法:利用[NSNotificationCenter defaultCenter]两个页面传递消息

主页面定义消息:

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


//子页面的消息,实现子页面操作后刷新列表
-(void)LuShuaXinTips:(NSNotification*)nofi
{
if ([[nofi.userInfo objectForKey:@"shuaxin"] intValue]==1) {
[self postSelfData];
[self postSecondData];
}
}


子页面:

定义一个标志位,如果更改就刷新主页面列表数据,否则就不进行操作

@property(copy,nonatomic)NSString* shuxinIndex;//刷新上一个界面的标志,如果是1就刷新


子页面进行了操作,更改标志位

self.shuxinIndex=@"1";


子页面销毁后,发送消息,避免子页面冲突:

-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:YES];
[[NSNotificationCenter defaultCenter]postNotificationName:@"LuShuaXinTips" object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:self.shuxinIndex,@"shuaxin", nil]];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: