代码之家  ›  专栏  ›  技术社区  ›  Bryan

UIImagePickerController Crashing Monotouch

  •  2
  • Bryan  · 技术社区  · 14 年前

    我正试图编写一个应用程序,但在使用uiimagepickercontroller时它经常崩溃。我想这可能是因为每次使用后我都没有处理拾音器,但它也会在第一次运行时冻结。通常我会拍一张照片,它只是冻结,从不要求“使用”照片。

    你有什么建议吗?这是我的密码。有人把这个弄好了吗?

     public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
    
            myPicker = new UIImagePickerController();
            myPicker.Delegate = new myPickerDelegate(this);
    
            myAlbumButton.Clicked += delegate {
                    if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)){
                        myPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
                        myPicker.AllowsEditing = true;
                        this.PresentModalViewController (myPicker, true);
                    }else{
                    Console.WriteLine("cannot get album");  
                }
            };
    
    
            myCameraButton.Clicked += delegate {
                if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
                    myPicker.SourceType = UIImagePickerControllerSourceType.Camera;
                    //myPicker.AllowsEditing = true;
                    this.PresentModalViewController (myPicker, true);
                }else{
                    Console.WriteLine("cannot get camera"); 
                }
    
            };
    
        }
    
    
        private class myPickerDelegate : UIImagePickerControllerDelegate
        {
            private TestView _vc;
    
            public myPickerDelegate ( TestView controller):base()
            {
                _vc = controller;   
            }
    
            public override void FinishedPickingImage (UIImagePickerController myPicker, UIImage image, NSDictionary editingInfo)
            {
                // TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
    
                _vc.myImageView.Image = image;
                myPicker.DismissModalViewControllerAnimated(true);
            }
     }
    
    2 回复  |  直到 14 年前
        1
  •  0
  •   Nikolai Sander    14 年前

    尝试使用BeginInvokeOnMainThread()从主线程调用事件处理程序代码。

        2
  •  0
  •   Daniel Benedykt    12 年前

    所以我的问题很相似。


    由于某些原因,应用程序每次在处理完图像后都会冻结,之后不会在任何断点处停止。

    我的解决办法是用这本书:

    http://www.scribd.com/doc/33770921/Professional-iPhone-Programming-with-MonoTouch-and-NET-C