最近遇到一個導航欄異常相關的問題,問題描述以下:新建一個viewcontroller 而後用導航 session
pushViewController展現出來, app
代碼以下: ide
//羣 spa
RCSGroupSettingVC *v = [[RCSGroupSettingVC alloc]initWithGroupID:self.sessionUri]; ip
v.hidesBottomBarWhenPushed = YES; ci
[self.navigationController pushViewController:v animated:YES]; get
而後邏輯層有一個模塊會向這個節目拋送一個通知,當收到這個通知後,這個節目會迅速從導航中pop出來, it
if (type == UI_RCSGroup_groupHasBeenDel) io
{ table
//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;
}
遇到這種問題的解決方法就是將拋送過來的通知的響應放到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;
}