だから、これは私を悩ませてきました。私がやりたいのは、複数の画像ビューがあるフォト コラージュ アプリを作成することです。画像ビューの上にボタンを配置します。ユーザーがボタンをクリックすると、カメラ ロールが表示され、画像を選択して配置できます。そのイメージビュー。私が抱えている問題は、ユーザーが画像を選択するたびに、複数の画像を宣言したにもかかわらず、1 つの画像ビューにしか配置されないことです。イメージはどんどん入れ替わります。以下は私のコードです。
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
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
提案??? 助けてください!!!