我实际上正在做一个简单的应用程序,它是 Mememe 类的。我的问题是在使用 UIActivityViewController
时尝试保存、共享等。但为什么它没有发生在这里?我想这是因为传递了一个空图像。但我真的不知道如何解决它。谁能帮帮我吗?
这是代码:
@IBAction func savingMyImage(sender: AnyObject) {
let image = UIImage()
let controller = UIActivityViewController(activityItems: [image], applicationActivities: nil)
presentViewController(controller, animated: true, completion: nil)
controller.completionWithItemsHandler = { (activity: String?, completed: Bool, items: [AnyObject]?, error: NSError?) -> Void in
if completed {
self.save()
self.dismissViewControllerAnimated(true, completion: nil)
}
}
}
感谢大家。
最佳答案
我在 iPad 2 和 iPad Air 模拟器上运行它并得到以下错误。我不需要为 iPhone 6 添加 popover 行
ViewControllerExp[1911:87261] *** 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7f94a24c3a80>) 应该在演示发生之前设置一个非零的 sourceView 或 barButtonItem。”
这段代码对我有用:
let image = UIImage()
let controller = UIActivityViewController(activityItems:[image], applicationActivities:nil)
//had to add this line to get it to work for the iPad simulator;
//it is not necessary for the iPhone 6 simulator
controller.popoverPresentationController?.sourceView = self.view
self.presentViewController(controller, animated:true, completion:nil)
关于IOS UIActivityViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33280518/