所以我将用户的图像上传到我的服务器。一旦用户选择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();
通话之前解除选择器,但是在上传完成之后它才被解雇,这是有效的。
如何在选择图像后立即取消选择器视图?
答案 0 :(得分: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
});
}
您的用户界面可以更新。
答案 1 :(得分: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();
});
答案 2 :(得分:0)
对于要更新的视图,我从新线程调用了UplodImage()
Thread t = new Thread (UploadImage);
t.Start ();