【问题标题】:UIImagePickerController does nothing when using camera after I hit "Use" button在我点击“使用”按钮后,UIImagePickerController 在使用相机时什么也不做
【发布时间】:2010-04-01 05:59:30
【问题描述】:

代码如下。

当我在拍照后点击“使用”按钮时……应用程序完全没有响应。任何想法我做错了什么?在 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];

}

【问题讨论】:

  • 您的“使用”按钮调用哪种方法?
  • “使用”按钮(来自内置相机控件)调用上面的 UIImagePickerControllerDelegate 方法。我能够让这个工作,但只有在移动“[picker dismissModalViewControllerAnimated:YES];”之后行到相同方法的顶部。但是,看起来还是有点呆滞。

标签: iphone objective-c camera uiimagepickercontroller


【解决方案1】:

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

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

尝试使用它。

编辑

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

【讨论】:

  • 如果 OP 在他们的项目中缺少那个括号,它甚至不会编译。
猜你喜欢
  • 2012-10-11
  • 2018-08-30
  • 2021-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多