UIImagePickerController does nothing when using camera after I hit “Use” button

社会主义新天地 提交于 2019-12-14 04:07:37

问题


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

}

回答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:

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 :)



来源:https://stackoverflow.com/questions/2558417/uiimagepickercontroller-does-nothing-when-using-camera-after-i-hit-use-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!