以下代码。
拍照后点击“使用”按钮...应用程序变得完全没有响应。我有什么想法我做错了吗?在UIViewController的视图上按下按钮时,将调用“addPlayer:”方法。
由于
- (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];
}
答案 0 :(得分:0)
我今天遇到过类似的问题。问题是我过度释放变量。这是我的代码崩溃的部分:
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 dismissModalViewControllerAnimated:YES];
如果它在你的项目中是这样的,那么它甚至运行真的很奇怪,在行的开头缺少'['。我正在使用
[self dismissModalViewControllerAnimated:YES];
尝试使用它。
修改强>
抱歉,没有看到问题的日期:)