Imagepickerviewコントローラーを使用して写真を選択し、imageviewを使用してuiviewに表示しましたが、私の問題はimageviewを使用して2つではなく1つの画像しか表示できないことです。2番目のものを選択すると、既存のものを置き換え続けます。2枚の写真を表示する方法を教えてください。
here is my source code.
-(void) ViewDidLoad
{
attachPhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
attachPhotoBtn.frame = CGRectMake(400, 125, 44, 44);
UIImage *attachImg = [UIImage imageNamed:@"album_add_off.png"];
[attachPhotoBtn setImage:attachImg forState:UIControlStateNormal];
[attachPhotoBtn addTarget:self action:@selector(attachPhoto:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:attachPhotoBtn];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 125, 64, 52)];
// imageView.backgroundColor = [UIColor greenColor];
[self.view addSubview:imageView];
}
}
- (IBAction)attachPhoto:(id)sender {
[sender setImage:[UIImage imageNamed:@"album_add.png"] forState:UIControlStateNormal];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,(NSString *)kUTTypeVideo,nil];
imagePicker.allowsEditing = NO;
// On iPad use pop-overs.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
_popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[_popover presentPopoverFromRect:attachPhotoBtn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
else
{
// On iPhone use full screen presentation.
// [[self presentingViewController] presentViewController:imagePicker animated:YES completion:nil];
}
newMedia = NO;
}
#pragma mark Image picker controller delegate methods
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
// [self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
[picker dismissViewControllerAnimated:NO completion:nil];
}