So this has been annoying the hell out of me. What I want to do is create a photo collage app where there are multiple image views and I will place buttons over the image views and when a user clicks the button it brings up the camera roll and you can choose an image and it places it in that image view. The problem I am having is that everytime a user chooses an image, it only places it in one image view even though I have declared more than one. The image just keeps getting replaced. Below is my code.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImagePickerController *imagePicker;
UIImagePickerController *imagePickerTwo;
}
@property (retain, nonatomic) IBOutlet UISwitch *toggleCamera;
@property (retain, nonatomic) IBOutlet UIImageView *imageViewOne;
@property (retain, nonatomic) IBOutlet UIImageView *imageViewTwo;
- (IBAction)buttonOne:(id)sender;
- (IBAction)buttonTwo:(id)sender;
@end
View Controller.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize toggleCamera;
@synthesize imageViewOne;
@synthesize imageViewTwo;
- (void)viewDidLoad
{ imagePicker = [[UIImagePickerController alloc] init];
imagePickerTwo = [[UIImagePickerController alloc] init];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setImageViewOne:nil];
[self setImageViewTwo:nil];
[self setToggleCamera:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[imageViewOne release];
[imageViewTwo release];
[toggleCamera release];
[super dealloc];
}
- (IBAction)buttonOne:(id)sender {
UIImagePickerController *imagePicker;
imagePicker = [[UIImagePickerController alloc] init];
if ([self.toggleCamera isOn]) {
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
}else {
imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate=self;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[self dismissModalViewControllerAnimated:YES];
self.imageViewOne.image=[info objectForKey:
UIImagePickerControllerOriginalImage];
}
- (IBAction)buttonTwo:(id)sender {
UIImagePickerController *imagePickerTwo;
imagePicker = [[UIImagePickerController alloc] init];
if ([self.toggleCamera isOn]) {
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
}else {
imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate=self;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerController2:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[self dismissModalViewControllerAnimated:YES];
self.imageViewTwo.image=[info objectForKey:
UIImagePickerControllerOriginalImage];
}
@end
Suggetions??? PLEASE HELPPPP!!!