Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CosmicChild87

macrumors newbie
Original poster
Nov 4, 2010
13
0
England
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
 

jvaneat

macrumors newbie
Nov 4, 2010
9
0
Colorado
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>
 

CosmicChild87

macrumors newbie
Original poster
Nov 4, 2010
13
0
England
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];
	 
}
 

jvaneat

macrumors newbie
Nov 4, 2010
9
0
Colorado
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.
 

CosmicChild87

macrumors newbie
Original poster
Nov 4, 2010
13
0
England
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 :(
 

CosmicChild87

macrumors newbie
Original poster
Nov 4, 2010
13
0
England
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!!!!
 
Last edited:

jvaneat

macrumors newbie
Nov 4, 2010
9
0
Colorado
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];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.