views:

54

answers:

2

Hi.

I want to make a game, where the user can touch a picture of a TV and then choose a picture from their photo library.

I had success working with UITextFields, adding them to my EAGLView as subviews But I haven't been able to do the same thing with an UIImagePickerController , which seems the only way to do what I want to do.

Any help is appreciated !

UPDATE

With the suggestion of zpasternack I managed to make the menu appear by adding the UIImagePickerControllerDelegate, UINavigationControllerDelegate and using this method:

- (void) chooseImageFromLibrary {
    if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.allowsEditing = YES;

 [self addSubview:imagePickerController.view];
 [imagePickerController viewWillAppear:YES];
 [imagePickerController viewDidAppear:YES];

}

I call the chooseImageFromLibrary method at the start. It shows the interface, but as soon as i hit cancel or choose the app stops.

Can anyone suggest me:

1) How to make the cancel and choose buttons work. 2) How to call the UIImagePickerController whenever I want ( by calling chooseImageFromLibrary again ??). 3) When the user hits choose..Where do i find the UIImage the user just picked to ?, how do i pick it ?

Thanks.

+1  A: 

I've never used one over an EAGLView, but UIImagePickerControllers are typically invoked with presentModalViewController, like:

- (void) chooseImageFromLibrary {
    if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.allowsEditing = YES;
    [self presentModalViewController:imagePickerController animated:YES];
}
zpasternack
I updated my question with your help, but i'm still stuck
José Joel.
A: 

Nervermind, problem solved. i just needed to overwrite some functions to make use of the UIImagePickerController.

José Joel.