UIVideoEditorController委托方法被调用两次

Sta*_*nov 5 ios uivideoeditorcontroller swift

我正在使用UIVideoEditorController,但是成功委托方法为我调用了两次。但是,所有传递的对象的所有指针都告诉它发送完全相同的数据。

let editor = UIVideoEditorController()
editor.videoMaximumDuration = 10.0
editor.videoQuality = .typeIFrame1280x720
editor.delegate = self
editor.videoPath = // some path goes here
self.present(editor, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

然后,以下方法将“ here”打印两次。

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    print("here")
    self.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

小智 5

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    editor.delegate = nil
    editor.dismiss(animated: true)
}
Run Code Online (Sandbox Code Playgroud)

  • 感谢您提供此代码片段,它可能会提供一些有限的短期帮助。正确的解释[将大大提高](//meta.stackexchange.com/q/114762)它的长期价值,通过展示*为什么*这是一个很好的问题解决方案,并将使其对未来的读者更有用其他类似的问题。请[编辑]您的答案以添加一些解释,包括您所做的假设。 (2认同)

小智 1

是的,我知道,这是不好的方式,但工作:)

var isSaved:Bool = false

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
   if(!isSaved) {
      print("here")
      self.isSaved = true
   }
       self.dismiss(animated: true, completion: nil)
   }
Run Code Online (Sandbox Code Playgroud)