当我按下“使用”后,使用相机时,UIImagePickerController不执行任何操作。纽扣 [英] UIImagePickerController does nothing when using camera after I hit "Use" button
问题描述
下面的代码。
当我在拍照后按下使用按钮时...该应用程序变得完全无响应。有任何想法我做错了吗?在UIViewController的视图上按下按钮时,将调用 addPlayer:方法。
When I hit the "Use" button after taking a picture ... the application becomes totally unresponsive. Any ideas what I'm doing wrong? The "addPlayer:" method is called when a button is pressed on the UIViewController's view.
谢谢
- (IBAction) addPlayers: (id)sender{
// Show ImagePicker
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
// If camera is available use it and display custom overlay view so that user can add as many pics
// as they want without having to go back to parent view
if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Grab original image
UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage];
// Resize photo first to reduce memory consumption
[self.photos addObject:[photo scaleToSize:CGSizeMake(200.0f, 300.0f)]];
// Enable *PLAY* button if photos > 1
if([self.photos count] > 1) btnStartGame.enabled = YES;
// Update player count label
lblPlayerCount.text = [NSString stringWithFormat:@"%d", [self.photos count]];
// Dismiss picker if not using camera
picker dismissModalViewControllerAnimated:YES];
}
推荐答案
I'今天也有类似的问题。问题是我过度释放了变量。这是我崩溃的代码部分:
I've had similar problem today. The problem was that I was over-releasing the variable. Here's the part of my code that was crashing:
UIImagePickerController *imagePicker = [[[UIImagePickerController alloc]init]autorelease];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES]
然后:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [[info objectForKey:@"UIImagePickerControllerOriginalImage"]fixOrientation];
[self performSelectorInBackground:@selector(uploadAPhoto:) withObject:image];
[picker release];
[self dismissModalViewControllerAnimated:YES];
}
我唯一要做的就是删除
[picker release] ;
行,现在它可以正常工作。
the only thing I did is deleting the [picker release]; line and now it works just fine.
看看您的代码,我会说这行有问题:
Looking at your code I'd say that there's a problem with this line:
picker dismissModalViewControllerAnimated:YES];
如果您的项目就是这样,那真是奇怪的是它甚至可以运行,但缺少 ['位于行首。而我正在使用
if that's how it is in your project, then it's really strange that it even runs, there's missing '[' at the beginning of the line. And I'm using
[self dismissModalViewControllerAnimated:YES];
尝试使用它。
编辑
对不起,没有看到问题的日期:)
Sorry, didn't see the date of the question :)
这篇关于当我按下“使用”后,使用相机时,UIImagePickerController不执行任何操作。纽扣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!