iPad Image Selection Problems

Discussion in 'iPhone/iPad Programming' started by CosmicChild87, Nov 4, 2010.

  1. macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    England
    #1
    Hi everyone,

    Im a complete N00b when it comes to iPhone/iPad programming and im trying to play with a program from tutorials on the net, and im currently trying to get an image picker to work

    I have a button that launches an image picker, in a sub view of my main view and this works well - but I can't seem to get the code to recognise when a user has selected an image.

    I have tried the following

    Code:
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    	[picker dismissModalViewControllerAnimated:YES];
    	theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
    }
    I don't get any errors when it runs - it just does nothing

    Apploiges if this is an obvious answer but any help or any pointers in the right direction would be very very appreciated

    Alan
     
  2. macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    Colorado
    #2
    You need to make sure that you have set the current view controller as an image picker delegate.

    If your using Interface Builder you can do it there. Otherwise, when you create the image picker do:

    Code:
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    
    And make sure the view controller can be a delegate. Open {Your}ViewController.h and add the UiImagePickerControllerDelegate portion like so:

    Code:
    @interface {Your}ViewController : UIViewController <UIImagePickerControllerDelegate>
    
     
  3. thread starter macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    England
    #3
    Thanks, I have both those things done still no joy :( - probably should have added it before, but here is the code i use to implement popover/image picker
    Code:
    -(IBAction)logoLoad:(id)sender{
    	NSLog(@"Running Image Picker Code");
    	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    	UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:picker];
    	picker.delegate = self; 
    
    	pop.delegate = self;
    	CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
    
    	NSLog(@"Rect Selected");
    	[pop presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    	
    	NSLog(@"Rect Made and presented");																
    	[pop setPopoverContentSize:CGSizeMake(200.0, 200.0)]; 
    	[picker release];
    	 
    }
    
     
  4. macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    Colorado
    #4
    Have you verified that the didFinishPickingMediaWithInfo method is getting called?

    If it is, try changing this:

    Code:
    [picker dismissModalViewControllerAnimated:YES];
    theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
    To this:

    Code:
    theimageView.image = [info valueForKey:UIImagePickerControllerOriginalImage];
    [picker dismissModalViewControllerAnimated:YES];
    
    UIImagePickerControllerOriginalImage is defined as a string constant.
     
  5. thread starter macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    England
    #5
    I had put an NSLog in as the first line, and it isnt being called at all :S

    Code:
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    	NSLog(@"Running after picking");
    	theimageView.image = [info valueForKey:UIImagePickerControllerOriginalImage];
    	[picker dismissModalViewControllerAnimated:YES];
    
    }
    
    Does nothing and outputs nothing to the debugger :(
     
  6. macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    Colorado
    #6
    In logoLoad try getting ride of [picker release];
     
  7. CosmicChild87, Nov 4, 2010
    Last edited: Nov 4, 2010

    thread starter macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    England
    #7
    Fantastic thank you!, how would i go about getting the popover to close once the image is selected?

    Alan

    It's ok i was being stupid again - thank you so much for your help!!!!
     
  8. macrumors newbie

    Joined:
    Nov 4, 2010
    Location:
    Colorado
    #8
    When you define pop, do this:

    Code:
    pop.tag = 200; // Use a number you like, or better still define a constant
    

    Then when you have found the image simply add this to didFinishPickingMediaWithInfo:

    Code:
    UIPopoverController *pop = (UIPopoverController *)[self.view viewWithTag:200];
    [pop removeFromSuperView];
    [pop release];
    
     

Share This Page