
至少这是它在iOS4中的工作方式.现在使用iOS5它只是处理它直到它完成,然后一切正常.但我希望那个微调器在那里让用户知道正在发生的事情,否则看起来它只是挂了.
所以我有这个:
- (voID) actionSheet: (UIActionSheet *)actionSheet dIDdismissWithbuttonIndex (NSInteger)buttonIndex { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = NO; // yada,yada,yada [self presentModalVIEwController:picker animated:YES]; [picker release];} 然后当用户选择“使用”时调用它:
- (voID) imagePickerController: (UIImagePickerController *)picker dIDFinishPickingMediawithInfo:(NSDictionary *)info { [self dismissModalVIEwControllerAnimated:YES]; [self performSelectorOnMainThread:@selector(processImage:) withObject:info waitUntilDone:NO]; animate = true;} 然后在缩略图旋转时调用此方法执行处理:
- (voID) processImage:(NSDictionary *)info{ UIImage *image = nil; Nsstring* mediaType = [info objectForKey:UIImagePickerControllerMediaType]; // processing of image animate = false; [activityImageVIEw stopAnimating]; [activityImageVIEw release]; [self.tableVIEw reloadData];} 就像我说的,它与iOS4完美配合,但是对于iOS5,没有这样的运气.那是什么交易?图像选择器最终被解雇,为什么不立即被解雇?
解决方法 我不确定为什么iOS4和iOS之间存在差异? iOS5就这一点而言.但是您对UI悬挂的描述与您显示的代码非常一致.主线程上的执行选择器就是这样做,在主线程上执行选择器,这是你要调用的线程.因为这个设置waitUntilDone:NO没有意义,因为它没有被发送到另一个线程,它只是按顺序运行.您可能只需交换订单就可以得到您想要的结果,例如:[self dismissModalVIEwControllerAnimated:YES];animate = true;[self performSelectorOnMainThread:@selector(processImage:) withObject:info waitUntilDone:NO];
但请注意,这最多会有风险,因为我假设//处理图像不包含并发.我更喜欢块并发.最重要的是,我喜欢嵌套块,以使并发易于遵循,例如:
-(voID)doSomeStuffInBackground{ // Prepare for background stuff dispatch_async(dispatch_get_global_queue(0,0),^{ // Do background stuff dispatch_async(dispatch_get_main_queue(),^{ // Update UI from results of background stuff }); });} 所以考虑到这一点,我会建议更像这样的东西:
-(voID)imagePickerController:(UIImagePickerController *)picker dIDFinishPickingMediawithInfo:(NSDictionary *)info{ [self dismissModalVIEwControllerAnimated:YES]; [self processImage:info];}-(voID)processImage:(NSDictionary *)info{ animate = true; UIImage *image = nil; Nsstring* mediaType = [info objectForKey:UIImagePickerControllerMediaType]; dispatch_async(dispatch_get_global_queue(0,^{ // processing of image here on background thread dispatch_async(dispatch_get_main_queue(),^{ // update UI here on main thread animate = false; [activityImageVIEw stopAnimating]; [activityImageVIEw release]; [self.tableVIEw reloadData]; }); });} 这会将主要工作卸载到后台线程,以使UI保持响应.
总结以上是内存溢出为你收集整理的为什么dismissmodalviewcontrolleranimated不会立即在ios5上解除UIImagePickerController?全部内容,希望文章能够帮你解决为什么dismissmodalviewcontrolleranimated不会立即在ios5上解除UIImagePickerController?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)