0

所以我正在将用户的图像上传到我的服务器。一旦用户在中选择图像,我就有以下代码UIImagePickerController

    public void Picked(object sender, UIImagePickerMediaPickedEventArgs e)
    {
        Console.WriteLine ("done picking");
        picker.DismissViewController (false, null);

        image.Image = e.Info [UIImagePickerController.OriginalImage] as UIImage;


        UploadImage (); //call the upload function
    }

这有效,除了我希望选择器在UploadImage();调用之前被解散,但直到上传完成后才会被解散。

如何在选择图像后立即关闭选择器视图?

4

3 回答 3

0

我建议您像这样通过 dispatchAsync 运行 UploadImage:

   public void Picked(object sender, UIImagePickerMediaPickedEventArgs e)
    {
        Console.WriteLine ("done picking");
        picker.DismissViewController (false, null);

        image.Image = e.Info [UIImagePickerController.OriginalImage] as UIImage;

        yourQueue = new DispatchQueue ("Image Uploading Queue");
        yourQueue.DispatchAsync (() => {

             UploadImage (); //call the upload function
        });
    }

这样你的 UI 就可以更新了。

于 2013-05-17T02:08:04.970 回答
0

尝试将您的 uploadImage 放入 GCD。

像这样的东西:

picker.DismissViewController (false, null);
image.Image = e.Info [UIImagePickerController.OriginalImage] as UIImage;

dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 

dispatch_async(concurrentQueue, ^{

    uploadImage();
});
于 2013-05-17T02:44:36.850 回答
0

为了更新视图,我UplodImage()从一个新线程中调用

Thread t = new Thread (UploadImage);
t.Start ();
于 2013-05-17T21:41:46.307 回答