iOS navigation (pop)返回按钮点击提示框
来源:互联网 发布:淘宝职业女套装. 编辑:程序博客网 时间:2024/06/04 19:06
想了一段时间,还是通过博客来记录自己开发学习的过程,也让自己坚持学习,坚持进步
想下载源码的猛戳这里
本文章主要讲的是,点击系统自带的navigation返回按钮,弹出AlertView,点击确认后,才返回上一个页面,如图所示
下面是第二个界面.m的代码,其中-(void)alertView是在.h中公开的方法,方便在NaviViewController这个类中调用
#import "ViewControllerB.h"@interface ViewControllerB ()@end@implementation ViewControllerB- (void)viewDidLoad { [super viewDidLoad]; self.title = @"第二页";}-(void)alertView{ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"返回" message:@"你愿意返回吗" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self.navigationController popViewControllerAnimated:YES]; }]; [alertVC addAction:cancelAction]; [alertVC addAction:sureAction]; [self presentViewController:alertVC animated:YES completion:nil];}
下面是NaviViewController这个类,继承于UINavigationController,主要在这个类中判断navigation自带的back按钮的点击事件,这里是点击back后弹出alertView,废话不多说,如下代码
#import "NaviViewController.h"#import "ViewControllerB.h"@interface NaviViewController ()<UIGestureRecognizerDelegate, UINavigationBarDelegate>//注意此类在appDelegate方法里面进行配置@end@implementation NaviViewController-(BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item{ UIViewController *vc = [self.viewControllers lastObject]; if ([vc isKindOfClass:[ViewControllerB class]]) { [(ViewControllerB *)vc alertView]; for (UIView *subView in [vc.navigationController.navigationBar subviews]) {//保证取消后左箭头颜色不变 if ([NSStringFromClass([subView class]) isEqualToString:@"_UINavigationBarBackIndicatorView"]) { [UIView animateWithDuration:0.25 animations:^{ subView.alpha = 1; }]; } } return NO; } return YES;}@end
对了在appDelegate中也需要进行配置
@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; _window.backgroundColor = [UIColor whiteColor]; [_window makeKeyAndVisible]; //注意NaviViewController是自己写得类 NaviViewController *navi = [[NaviViewController alloc]initWithRootViewController:[ViewController new]]; navi.navigationBar.backgroundColor = [UIColor blueColor]; _window.rootViewController = navi; return YES;}
当然这里没有静止手势右滑返回上一界面,需要这功能的自行百度
1 0
- iOS navigation (pop)返回按钮点击提示框
- IOS navigation 返回按钮 不显示文字
- iOS _隐藏Navigation 返回按钮
- iOS - 统一设置Navigation的返回按钮
- Navigation返回按钮自定义
- iOS 使用使用Swizzling 全局修改Navigation的返回按钮
- iOS 最简单的修改navigation 返回按钮的方法
- Android点击返回按钮弹出提示“点击两次退出程序”
- 【iOS】返回崩溃:nested pop animation can result in corrupted navigation bar nested pop animation can re
- 去掉navigation返回按钮文字
- ios 滑动返回 pop
- iOS POP返回总结
- iOS tabbar和navigation组合,点击item两次,会pop到上一个页面,解决不让控制器跳转的方法
- iOS navigation布局 按钮修改
- js点击按钮返回一个确认框
- Android 点击按钮弹出提示框实例
- iOS pop返回时崩溃
- iOS自定制导航栏返回按钮或者隐藏导航栏pop手势失效解决方案
- 浅尝安卓事件分发机制
- 开通博客的第一帖
- Git(二)基本操作
- 去除Win10资源管理器中快速访问的“最近使用的文件”和“常用文件夹”
- 周易六十四卦——否卦
- iOS navigation (pop)返回按钮点击提示框
- Android 开发中百度地图运行一段时间地图轨迹不更新的问题
- 由ssh框架引起的set里的对象排序问题
- 人见人爱A+B(1)
- Python修改当前工作目录
- #Objective - C - UI-design - 第四天 -UIKit框架-UIKit-事件手势-刮刮乐小游戏
- 说完电调就是螺旋桨了
- 含义while((ch=getchar())!='#'){},while(ch=getchar(),ch!='#'),while(ch=getchar() && ch!='#')
- centos 安装VMwareTools