在我点击“使用”后使用相机时 UIImagePickerController 不执行任何操作按钮

发布于 2024-08-27 11:52:16 字数 1542 浏览 3 评论 0原文

代码如下。

当我拍照后点击“使用”按钮时......应用程序变得完全没有响应。有什么想法我做错了吗?当按下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-09-03 11:52:16

我今天也遇到了类似的问题。问题是我过度释放了变量。这是我的代码崩溃的部分:

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];

尝试使用它。

编辑

抱歉,没有看到问题的日期:)

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]

and then:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  UIImage *image = [[info objectForKey:@"UIImagePickerControllerOriginalImage"]fixOrientation];
  [self performSelectorInBackground:@selector(uploadAPhoto:) withObject:image];

  [picker release];
  [self dismissModalViewControllerAnimated:YES];
}

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];

Try using that.

Edit

Sorry, didn't see the date of the question :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文