Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-15-2011, 02:40 AM   #1 (permalink)
k2c
Registered Member
 
Join Date: Oct 2009
Posts: 26
k2c is on a distinguished road
Unhappy How to change multiple UIImageView from UIImagePickerController?

Hi all

I have 5 buttons and 5 UIImageViews. I would like to change each UIImageView from photo library. When I push #1 button and choose a photo from photo library, it changes #1 UIImageView. However, when I push #2 button to change #2 UIImageView, it changes #1 UIImageView....Anybody know how to fix this??

Code:
-(IBAction) getPhoto1:(id) sender1 {
	
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	
	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker animated:YES];
	
}

-(IBAction) getPhoto2:(id) sender2 {
	
	UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
	picker2.delegate = self;

	picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker2 animated:YES];
	
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img  editingInfo:(NSDictionary *)editInfo {
  
    if(getPhoto1){
    //////create NSData
	NSData *ImageData = UIImageJPEGRepresentation(img, 0.9);
	[[NSUserDefaults standardUserDefaults] setObject:ImageData forKey:@"image"];
	
	imageView1.image = img;
        
    }
    
    if(getPhoto2){
        //////create NSData
        NSData *ImageData2 = UIImageJPEGRepresentation(img, 0.9);
        [[NSUserDefaults standardUserDefaults] setObject:ImageData2 forKey:@"image2"];
        
        imageView2.image = img;
        
    }
    
    
	
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
}
k2c is offline   Reply With Quote
Old 05-15-2011, 03:13 AM   #2 (permalink)
iOSDeveloperz
 
iOSDeveloperz's Avatar
 
Join Date: Apr 2011
Location: INDIA
Posts: 99
iOSDeveloperz is on a distinguished road
Send a message via Skype™ to iOSDeveloperz
Default

Quote:
Originally Posted by k2c View Post
Hi all

I have 5 buttons and 5 UIImageViews. I would like to change each UIImageView from photo library. When I push #1 button and choose a photo from photo library, it changes #1 UIImageView. However, when I push #2 button to change #2 UIImageView, it changes #1 UIImageView....Anybody know how to fix this??

Code:
-(IBAction) getPhoto1:(id) sender1 {
	
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	
	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker animated:YES];
	
}

-(IBAction) getPhoto2:(id) sender2 {
	
	UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
	picker2.delegate = self;

	picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker2 animated:YES];
	
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img  editingInfo:(NSDictionary *)editInfo {
  
    if(getPhoto1){
    //////create NSData
	NSData *ImageData = UIImageJPEGRepresentation(img, 0.9);
	[[NSUserDefaults standardUserDefaults] setObject:ImageData forKey:@"image"];
	
	imageView1.image = img;
        
    }
    
    if(getPhoto2){
        //////create NSData
        NSData *ImageData2 = UIImageJPEGRepresentation(img, 0.9);
        [[NSUserDefaults standardUserDefaults] setObject:ImageData2 forKey:@"image2"];
        
        imageView2.image = img;
        
    }
    
    
	
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
}
This can only be the case when both of your if conditions are executing, now i may not be able to tell you anything unless you tell me what are getPhoto1 and getPhoto2
__________________
iOS Developerz
You Think, We Create...

http://iosdeveloperz.com/

View our latest apps
iOSDeveloperz is offline   Reply With Quote
Old 05-15-2011, 03:24 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

what about

Code:
int butSel = 0;

-(IBAction) getPhoto1:(id) sender1 {
	butSel = 1;
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	
	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker animated:YES];
	
}

-(IBAction) getPhoto2:(id) sender2 {

	butSel = 2;
	UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
	picker2.delegate = self;

	picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker2 animated:YES];
	
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img  editingInfo:(NSDictionary *)editInfo {
  
    if(butSel==1){
    //////create NSData
	NSData *ImageData = UIImageJPEGRepresentation(img, 0.9);
	[[NSUserDefaults standardUserDefaults] setObject:ImageData forKey:@"image"];
	
	imageView1.image = img;
        
    }
    
    if(butSel == 2){
        //////create NSData
        NSData *ImageData2 = UIImageJPEGRepresentation(img, 0.9);
        [[NSUserDefaults standardUserDefaults] setObject:ImageData2 forKey:@"image2"];
        
        imageView2.image = img;
        
    }
    
    
	
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
}
__________________
dany_dev is offline   Reply With Quote
Old 05-15-2011, 03:28 AM   #4 (permalink)
k2c
Registered Member
 
Join Date: Oct 2009
Posts: 26
k2c is on a distinguished road
Default

Thank you for quick reply, iOSDeveloperz!

I have one long strip photo. I divided it to 5 UIImageViews, so getPhoto1 and getPhoto2 are photos from left to right and there are photo3, photo4, photo5.

-(IBAction) getPhoto1id) sender1 is attached to Button1.

Are these your are asking?
k2c is offline   Reply With Quote
Old 05-15-2011, 03:35 AM   #5 (permalink)
k2c
Registered Member
 
Join Date: Oct 2009
Posts: 26
k2c is on a distinguished road
Default

Great! dany_dev! You solved it! Thank you very much!!!
k2c is offline   Reply With Quote
Old 12-02-2011, 02:24 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 1
zeropt7 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
what about

Code:
int butSel = 0;

-(IBAction) getPhoto1:(id) sender1 {
	butSel = 1;
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	
	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker animated:YES];
	
}

-(IBAction) getPhoto2:(id) sender2 {

	butSel = 2;
	UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
	picker2.delegate = self;

	picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker2 animated:YES];
	
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img  editingInfo:(NSDictionary *)editInfo {
  
    if(butSel==1){
    //////create NSData
	NSData *ImageData = UIImageJPEGRepresentation(img, 0.9);
	[[NSUserDefaults standardUserDefaults] setObject:ImageData forKey:@"image"];
	
	imageView1.image = img;
        
    }
    
    if(butSel == 2){
        //////create NSData
        NSData *ImageData2 = UIImageJPEGRepresentation(img, 0.9);
        [[NSUserDefaults standardUserDefaults] setObject:ImageData2 forKey:@"image2"];
        
        imageView2.image = img;
        
    }
    
    
	
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
}
Thanks a lot! You solved my problem, I did a little bit modification on the code, it works out perfectly on iOS 4.3, however it freeze on iOS 5.0 after Ive clicked "choose" for an image. Please help.

Code:
int butSel = 0;
//choose left photo button pressed
-(IBAction)showPictureControlsLeft:(id)sender  {
	
	butSel = 1;
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	// Allow editing of image ?
    picker.allowsEditing = YES;
	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker animated:YES];
}

//choose right photo button pressed
-(IBAction)showPictureControlsRight:(id)sender  {
	
	butSel = 2;
	UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
	picker2.delegate = self;
    // Allow editing of image ?
    picker2.allowsEditing = YES;
	picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
	
	[self presentModalViewController:picker2 animated:YES];	
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    if(butSel==1){
        previewImageViewLeft.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        //[self applyDefaults];
        //quartzView.hidden=YES;
        
    }
    
    if(butSel == 2){
        previewImageViewRight.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        //[self applyDefaults];
        //quartzView.hidden=YES;
        
    }
	
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
}

Last edited by zeropt7; 12-02-2011 at 03:13 AM.
zeropt7 is offline   Reply With Quote
Reply

Bookmarks

Tags
multiple, uiimagepickercontroller, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 370
6 members and 364 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0