0
MonoTouchで作成したiPadアプリケーションに問題があります。メソッド "SelectPicture"を呼び出した後、メソッド "TakePicture"を呼び出してアプリケーションがクラッシュする "parent.PresentModalViewController(picker、true);"私が "TakePicture"メソッドを繰り返し呼び出すと、何の問題もありません。Monotouch NSInvalidArgumentException Camera
"NSInvalidArgumentException理由: アプリケーションがターゲットにnilモーダルビューコントローラを表示しようとしました。"
public static class Camera
{
static UIImagePickerController picker;
static Action<NSDictionary> _callback;
static UIPopoverController popover;
static void Init()
{
if (picker != null)
return;
picker = new UIImagePickerController();
picker.Delegate = new CameraDelegate();
}
public static void TakePicture (UIViewController parent, Action<NSDictionary> callback)
{
Init();
picker.SourceType = UIImagePickerControllerSourceType.Camera;
_callback = callback;
Console.WriteLine("Controller TEST");
parent.PresentModalViewController (picker, true);
}
public static void SelectPicture (UIViewController parent, Action<NSDictionary> callback)
{
if(Utils.isIpad()){
picker = new UIImagePickerController();
popover = new UIPopoverController(picker);
picker.Delegate = new CameraDelegate();
_callback = callback;
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
picker.ContentSizeForViewInPopover = new SizeF(parent.View.Frame.Width,parent.View.Frame.Height);
if(popover != null)
popover.PresentFromRect(new Rectangle(0,0,1000,1),
parent.View,UIPopoverArrowDirection.Any,true);
}else{
Init();
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
_callback = callback;
parent.PresentModalViewController (picker, true);
}
}
class CameraDelegate : UIImagePickerControllerDelegate {
public override void FinishedPickingMedia (UIImagePickerController picker, NSDictionary info)
{
var cb = _callback;
_callback = null;
picker.DismissModalViewControllerAnimated (true);
cb (info);
if(popover != null && popover.PopoverVisible){
popover.Dismiss(true);
popover.Dispose();
Console.WriteLine("DISPOSE");
}
picker.Dispose();
}
}
}
ありがとうございました。