在我点击“使用”后使用相机时 UIImagePickerController 不执行任何操作按钮
代码如下。
当我拍照后点击“使用”按钮时......应用程序变得完全没有响应。有什么想法我做错了吗?当按下 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];
}
Code below.
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.
Thanks
- (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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我今天也遇到了类似的问题。问题是我过度释放了变量。这是我的代码崩溃的部分:
然后:
我做的唯一一件事就是删除
[选择器发布];
线,现在工作得很好。
看看你的代码,我会说这一行有问题:
如果这就是你的项目中的情况,那么它甚至运行起来真的很奇怪,在该行的开头缺少“[”。我正在使用
尝试使用它。
编辑
抱歉,没有看到问题的日期:)
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:
and then:
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:
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
Try using that.
Edit
Sorry, didn't see the date of the question :)