所以这一直让我很烦。我想做的是创建一个照片拼贴应用程序,其中有多个图像视图,我将在图像视图上放置按钮,当用户单击按钮时,它会调出相机胶卷,您可以选择一个图像并将其放入那个图像视图。我遇到的问题是,每次用户选择图像时,即使我声明了多个图像,它也只会将其放置在一个图像视图中。图像只是不断被替换。下面是我的代码。
视图控制器.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
查看控制器.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
建议???请帮助!