LoginSignup
2
2

More than 5 years have passed since last update.

PromotionらしくUIImagePickerControllerを使う方法

Posted at

PromotionにはModalなViewControllerの呼び出しと、それが閉じた時に開いた側のViewControllerに値を渡す作法としてon_returnメソッドが用意されている。

その作法を、既存のUIViewControllerのサブクラスでも使う方法の説明。
といっても、UIImagePickerControllerでしかまだ試していない。

image_picker_screen.rb
class ImagePickerScreen < UIImagePickerController
  include ProMotion::ScreenModule

  def init
    if super
      self.delegate = self
    end
    self
  end

  def imagePickerController(picker, didFinishPickingMediaWithInfo:info)
    close value: :ok, picker: picker, info: info
  end

  def imagePickerControllerDidCancel(picker)
    close value: :cancel, picker: picker
  end

end

中身はdelegateで終了時に呼ばれるメソッドの中で、ProMotionのcloseをよんで、必要なパラメータを渡しているだけ。
今回はUIImagePickerCotrollerなので、UIImagePickerControllerDelegateのメソッドを実装している。
delegateを自らに実装してもにょもにょするのは問題ないのだろうか... 問題を指摘して欲しくて、とりあえず書いた。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2