呈现UIActivityViewController时发出警告

Fab*_*ian 2 ios uistoryboard swift xcode6

当我提出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)
}
Run Code Online (Sandbox Code Playgroud)

这个函数被一个调用UILongPressGestureRecognizer.请注意,我正在使用具有以下层次结构的storyboard:

TabBarController>(关系)>> NavigationController(关系) TableViewController>>(显示) TableViewController>>(显示)> ViewController.

演示文稿发生在最后一个ViewController上.

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

编辑

UILongPressGestureRecognizer 多次调用触摸事件,导致警告

Jua*_*lez 7

从你的问题很难说,但是在这种情况发生时是否还有一些其他的视图控制器?例如和行动表或其他?

无论如何,试试这个:

    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)
    }
Run Code Online (Sandbox Code Playgroud)

  • 不,那时没有任何其他视图控制器.你的代码完美地向我展示了func被快速连续调用了两次.一旦触摸开始,一次触摸结束.卫生署! (2认同)