【问题标题】:UIVideoEditorController delegate method called twiceUIVideoEditorController 委托方法调用了两次
【发布时间】:2018-06-11 10:40:19
【问题描述】:

我正在使用 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)

然后下面的方法打印“这里”2次。

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

【问题讨论】:

  • 当我链接到 iOS 13 时,即使用 Xcode 11 构建时,我看到了这个错误。如果我使用 Xcode 10 或更早版本构建,回调只为我调用一次。

标签: ios swift uivideoeditorcontroller


【解决方案1】:
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    editor.delegate = nil
    editor.dismiss(animated: true)
}

【讨论】:

  • 感谢您提供此代码 sn-p,它可能会提供一些有限的短期帮助。一个正确的解释would greatly improve 其长期价值,通过展示为什么这是解决问题的好方法,并将使其对未来有其他类似问题的读者更有用。请edit您的回答添加一些解释,包括您所做的假设。
【解决方案2】:

是的,我知道,这种方法很糟糕,但可以工作:)

var isSaved:Bool = false

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

【讨论】:

    【解决方案3】:

    您能否调试一下当用户离开屏幕时使用 UIVideoEditorController 的 UIViewController 是否正确重新分配。就像离开屏幕或从屏幕返回后一样。

    可能是你的 UIViewController 在内存中的一个对象,这就是你的方法被调用两次的原因。

    调试

    • 为你的 UIViewController 创建deinit{ print("deallocating") }
    • 在打印时添加断点。
    • 然后确保调用 deinit。

    希望对您有所帮助。 :)

    【讨论】:

      【解决方案4】:

      这对我有用

      - (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath {
      
          [editor dismissViewControllerAnimated:YES completion:^{
              NSLog(@"path = %@", editedVideoPath);
          }];    
      }
      

      【讨论】:

        猜你喜欢
        • 2013-11-22
        • 2011-02-07
        • 1970-01-01
        • 1970-01-01
        • 2018-06-27
        • 2014-07-03
        • 2013-07-10
        • 2015-04-11
        • 2012-04-08
        相关资源
        最近更新 更多