swift自定义导航控制器返回按钮事件
来源:互联网 发布:云计算大数据时代 编辑:程序博客网 时间:2024/06/05 23:55
最近在项目中碰到点击返回按钮时要先进行确认的需求,网上度了一下找到了相应的解决方案(代码下载地址:https://github.com/onegray/UIViewController-BackButtonHandler)。
不是自己写的代码,就不白话了,简单说一下用法:GitHub上下载地址后,将下载的代码导入到自己的项目中(我是直接拖进去的),代码是Objective-C的,所以需要在头文件中导入.h文件;然后在自己的控制器中重写navigationShouldPopOnBackButton方法即可。
我的控制器重写navigationShouldPopOnBackButton方法如下,供参考:
override func navigationShouldPopOnBackButton() -> Bool {
let alertView = LGAlertView(title: "", message: "退出支付将取消此次操作,点‘确认’继续退出,点‘取消’继续此次操作", style: .alert, buttonTitles: ["确定"], cancelButtonTitle: "取消", destructiveButtonTitle: nil, actionHandler: {
(alertView, text, buttonIndex) in
if buttonIndex == 0 {
var viewController:UIViewController?
for index in 0..<(self.navigationController?.viewControllers.count)! {
if self.navigationController?.viewControllers[index] is 自己的控制器类名 {
viewController = self.navigationController?.viewControllers[index]
}
}
self.navigationController?.popToViewController(viewController!, animated: true)
}
}, cancelHandler: nil, destructiveHandler: nil)
alertView.show(animated: true, completionHandler: nil)
return false
}
let alertView = LGAlertView(title: "", message: "退出支付将取消此次操作,点‘确认’继续退出,点‘取消’继续此次操作", style: .alert, buttonTitles: ["确定"], cancelButtonTitle: "取消", destructiveButtonTitle: nil, actionHandler: {
(alertView, text, buttonIndex) in
if buttonIndex == 0 {
var viewController:UIViewController?
for index in 0..<(self.navigationController?.viewControllers.count)! {
if self.navigationController?.viewControllers[index] is 自己的控制器类名 {
viewController = self.navigationController?.viewControllers[index]
}
}
self.navigationController?.popToViewController(viewController!, animated: true)
}
}, cancelHandler: nil, destructiveHandler: nil)
alertView.show(animated: true, completionHandler: nil)
return false
}
阅读全文
1 0
- swift自定义导航控制器返回按钮事件
- 自定义导航控制器返回按钮
- iOS7导航控制器自定义返回按钮
- Swift自定义导航栏返回按钮
- 自定义导航栏返回按钮点击事件
- Swift- 自定义导航栏背景、标题和返回按钮属性
- 自定义导航返回按钮
- iOS 隐藏导航控制器返回按钮
- 自定义导航条返回按钮
- 自定义导航栏返回按钮
- 自定义导航栏返回按钮
- 自定义导航栏返回按钮
- Swift之UITabBarController 导航控制器的自定义
- 自定义导航控制器的滑动返回效果
- 自定义封装导航栏左右按钮点击事件和特定风格的控制器供多个控制器继承—— 当很多导航页面有相似的导航条时
- 导航返回按钮的事件处理
- ionic3 导航栏返回按钮事件设置
- 自定义按钮实现Android 返回按钮事件
- oracle查看service name,SID,以及sys用户和system用户区别。
- 各种算法概念
- jsp编译报错
- three.js 05-02 之 CircleGeometry 几何体
- 安卓上方滑动条目
- swift自定义导航控制器返回按钮事件
- 设置mysql允许外部IP连接的解决方法
- Win10系统中Keras安装指南
- oracle日期函数大全
- 动态规划之数位DP专题
- 互联网广告综述之点击率特征工程
- linux less 命令
- Pandas 基本用法
- 微信支付的那些坑