我试图在导航到前一个控制器之前提示 UIAlertView,并在用户决定留在同一视图控制器上时阻止导航。使用CCT后退按钮操作助手 https://github.com/weipin/CCTBackButtonAction, UIAlertView 可以轻松生成,但我面临的唯一问题是它会将后退按钮的颜色更改为灰色,就像单击任何禁用的 UIBarButton 控件一样。但是,单击导航栏上的任意位置都会恢复其原始颜色。那么我怎样才能防止改变它的颜色呢?
我现在就是这样做的。
在 CustomNavigationContoller.m 中
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
BOOL should = [[CCTBackButtonActionHelper sharedInstance] navigationController:self navigationBar:navigationBar shouldPopItem:item];
if (!should) {
return NO;
}
return [super navigationBar:navigationBar shouldPopItem:item];
}
在 CustomViewController.m 中
#pragma mark - Back button
- (void)cct_navigationBar:(UINavigationBar *)navigationBar willPopItem:(UINavigationItem *)item {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Are you sure you want to go back?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertView show];
}
#pragma mark - Alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.cancelButtonIndex == buttonIndex) {
return;
}
[self.navigationController popViewControllerAnimated:YES];
}
有一个非常简单的解决方案。
我宁愿让苹果解决这个问题,但你的问题(和我的)可能是
通过插入以下内容来解决navigationBar:shouldPopItem:
auto item = navigationBar.topItem;
item.hidesBackButton = YES;
item.hidesBackButton = NO;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)