dismissModalViewControllerAnimated之后的动作

时间:2012-01-11 11:31:52

标签: objective-c ios5 uiimage

使用相机选择照片后,我将其保存为NSData。这需要一段时间,我不希望我的用户等待它。我希望它发生在后台。我的问题是,在调用“dismissModalViewControllerAnimated:NO”之后执行方法是否明智。

这是我的代码,输出以下内容:

DEBUG1
DEBUG2
debug4
debug5
debug6
debug3

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

NSLog(@"debug1");

// Save image in the normal photo album
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

NSLog(@"debug2");

[[MySingleton sharedSingleton] addImg:image];

NSLog(@"debug3");
[picker dismissModalViewControllerAnimated:NO];

[_delegate startStep2];

}

-(void) addImg: (UIImage *) img {

NSLog(@"debug4");

NSData *jpegData = UIImageJPEGRepresentation([img rotateAndScaleFromCameraWithMaxSize:1500.0], 0.9f);

NSLog(@"debug5");

image   = [[NSData alloc] initWithData:jpegData];

NSLog(@"debug6");
}

我可以先解除viewcontroller而不是其他东西,或者这不是一个好方法吗?

编辑//我通过这样做解决了等待问题:

[[MySingleton sharedSingleton] performSelectorInBackground:@selector(addImg:) withObject:image];

3 个答案:

答案 0 :(得分:0)

一旦你有retained所有必需的信息,我认为你可以解雇选择器。

答案 1 :(得分:0)

最好先做一些事情,然后解雇视图控制器。您可以为用户添加活动指示器以了解处理是否继续..

答案 2 :(得分:0)

[[MySingleton sharedSingleton] performSelectorInBackground:@selector(addImg :) withObject:image];

做了诀窍..