使用MonoTouch创建的iPad应用程序出现问题。我的应用程序崩溃通过调用方法“TakePicture”行“parent.PresentModalViewController(picker,true);”,在调用方法“SelectPicture”之后。如果我反复调用方法“TakePicture”,我没有问题。
返回的错误是:“NSInvalidArgumentException原因: 应用程序试图在目标上显示一个零模态视图控制器。“。
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();
}
}
}
感谢您的帮助。
答案 0 :(得分:1)
我解决了我的问题。 我删除了这一行:
picker.Dispose();