ios - 停止 UI 警报控制器返回上一个视图
问题描述
我的应用程序中有一个 UIAlertView。但是出于某种奇怪的原因,如果我决定按下警报视图上的“返回”按钮。它实际上把我带到了前一个视图控制器,而不是简单地解除警报。
我怎样才能防止这种情况?如果按下后退按钮,我只想隐藏警报
问题视频:https ://youtu.be/fhb-REuQiyg
这是警报的功能:
let alertController = UIAlertController.init(title: "Open Map", message: "", preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "Google Maps", style: .default, handler: { (action) in
self.googleMapsOpen()
}))
alertController.addAction(UIAlertAction.init(title: "Apple Maps", style: .default, handler: { (action) in
self.appleMapsOpen()
}))
alertController.addAction(UIAlertAction.init(title: "Back", style: .default, handler: { (action) in
self.dismiss(animated: true, completion: nil)
}))
self.present(alertController, animated: true) {
}
解决方案
删除这个
self.dismiss(animated: true, completion: nil)
这里
alertController.addAction(UIAlertAction.init(title: "Back", style: .default, handler: { (action) in
self.dismiss(animated: true, completion: nil)
}))
当您按下操作时,警报控制器会自动关闭,因此您的书面关闭也会关闭当前呈现的 vc
推荐阅读
- postgresql - postgresql通过过程从csv文件复制到windows中的表中
- php - 如何在 Laravel 8 中创建自定义电子邮件验证
- reactjs - 使用 envoy 作为代理时,如何在 grpc-go(backend) 和 react(grpcweb frontend) 之间配置一种方式 tls?
- firebase - Firestore + Vue:刷新页面时,如何避免数据显示延迟?
- python - 当我似乎正在填写参数时,为什么会收到 TypeError?
- typescript - 如何通过映射类型创建类型以在打字稿中使用`Map<>`
- phpword - 将 DOCX 数据插入模板
- javascript - 如果发生错误,如何调用两次 API?
- python - 熊猫:如何将整数出生日期转换为年龄
- lodash - Lodash 4:如果对象属性包含字符串的某个部分,如何省略它们?