最近遇到一个导航栏异常相关的问题,问题描述如下:新建一个viewcontroller 然后用导航
pushViewController展示出来,
代码如下:
//群
RCSGroupSettingVC *v = [[RCSGroupSettingVC alloc]initWithGroupID:self.sessionUri];
v.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:v animated:YES];
然后逻辑层有一个模块会向这个节目抛送一个通知,当收到这个通知后,这个节目会迅速从导航中pop出来,
if (type == UI_RCSGroup_groupHasBeenDel)
{
//id<RCSParticipant> group = [param objectForKey:@"param"];
NSString * groupId = [para objectForKey:@"param"];
if ([groupId isEqualToString:_group.ID])
{
NSMutableArray *navigationStack = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];
if ([navigationStack containsObject:self])
{
id objc = [(RCSBaseNavigationController *)self.navigationController getViewControllerByClass:[RCSMsgBoxViewController class]];
if (objc)
{
// 消息盒子
[self.navigationController popToViewController:objc animated:NO];
}
}
else{
_bGroupIsDelete = YES;
}
}
return;
}
此时由于pushviewcontroller到导航栏中要进行一下操作,迅速的pop到其他viewcontroller或者popTorootviewcontroller就会引起,导航栏的错乱,或者界面释放后刷新不了,依然展示在导航栏中,再次操作该界面就会引起崩溃。
遇到这种问题的解决方法就是将抛送过来的通知的响应放到viewdidappear中处理,让导航栏的pushviewcontroller处理完,界面展示出来后,所有初始化处理完后,在popToViewcontroller,此时就不会有异常了。
//通知里面设置一个变量,表示要popviewcontroller了
if (type == UI_RCSGroup_groupHasBeenDel)
{
//id<RCSParticipant> group = [param objectForKey:@"param"];
NSString * groupId = [para objectForKey:@"param"];
if ([groupId isEqualToString:_group.ID])
{
_bGroupIsDelete = YES;
}
}
return;
}
//在
viewDidAppear方法中处理popviewcontroller
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (_bGroupIsDelete)
{
NSMutableArray *navigationStack = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];
if ([navigationStack containsObject:self])
{
id objc = [(RCSBaseNavigationController *)self.navigationController getViewControllerByClass:[RCSMsgBoxViewController class]];
if (objc)
{
// 消息盒子
[self.navigationController popToViewController:objc animated:NO];
}
}
}
_bHaveDidAppear = YES;
}