ios - UIAlertController 失败后打开 UIActivityViewController
问题描述
我需要一个功能,通过电子邮件共享一些 .csv 文件。
因此,首先我要将 .csv 文件保存到文档目录,然后尝试打开 UIActivityViewController。
但这失败了。
这是我的代码:
saveprojectfile() // Here are the UIAlertController calls, these calls needs some time
let activityVC = UIActivityViewController(activityItems: [path], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completeion: nil)
任何提示,为什么这不起作用?
谢谢!
解决方案
代码在显示UIActivityViewController
时正在执行UIAlertController
,但在显示警报控制器时无法显示。我原以为这会崩溃。
您应该在警报控制器操作的完成处理程序中显示活动视图控制器。
// Code for alert controller (was in your saveprojectfile() function
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: yourFunction)) // OK action handler added
self.present(alert, animated: true, completion: nil) // Completion handler here will not work as it fires on completion of presenting, not dismissing
func yourFunction() {
// Present the action controller here
let activityVC = UIActivityViewController(activityItems: [path], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completeion: nil)
}
推荐阅读
- python - 在 mongodb 集合中导入 json?
- swift - Swift 5 Scanner 类很慢
- r - 从 mable 中提取模型描述
- php - PHP Strip_Tags 仅调用数组中的第一项
- flutter - Flutter run -d all 不会启动 chrome
- wordpress - 如果用户不拥有目录,如何通过 git 远程推送更新 Wordpress 文件?
- azure-devops - 安装 SSH 密钥任务在作业后阶段失败
- azurekinect - 获取 FaceModel - Azure Kinect
- mongodb - brew install mongo 在 ubuntu 18.04 中不起作用
- react-native - 反应导航 - “未定义不是一个对象(评估'Component.router.getStateForAction')”