呈现UIActivityViewController时出现警告

当我提出一个UIActivityController使用下面的代码我得到,但呈现,但控制台显示“ Warning: Attempt to present <UIActivityViewController: 0x7f8788e7aed0> on <MyApp.CustomTableViewController: 0x7f8788e3db60> which is already presenting (null) ”。

 @IBAction func shareImage(sender: AnyObject) { let images: [UIImage] = [image.image!] let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil) self.presentViewController(activityViewController, animated: true, completion: nil) } 

这个func被UILongPressGestureRecognizer 。 请注意,我使用以下层次结构的故事板:

TabBarController >(Relationship)> NavigationController >(Relationship)> TableViewController >(Show)> TableViewController >(Show)> ViewController

演示发生在最后一个ViewController上。

我很确定这是关于层次结构,哪个控制器当前呈现(以及如何)以及哪个控制器负责呈现UIActivityViewController

编辑

UILongPressGestureRecognizer touch事件被多次调用,导致警告

从你的问题来看很难说,但是现在有没有其他的视图控制器呢? 例如和行动表或其他?

无论如何试试这个:

  if self.presentedViewController != nil { self.dismissViewControllerAnimated(false, completion: { [unowned self] in self.presentViewController(activityViewController, animated: true, completion: nil) }) }else{ self.presentViewController(activityViewController, animated: true, completion: nil) }