我在一个视图控制器中有两个图像,它们已被选中UIImagePickerController
:
ChoosePhotosViewController.h
@interface PickPhotosViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *pickedImage1; // image 1
@property (strong, nonatomic) IBOutlet UIImag8eView *pickedImage2; // image 2
- (IBAction)pickImage1:(id)sender; // button that picks up the first image
- (IBAction)pickImage2:(id)sender; // button that picks up the seconds image
- (IBAction)nextButton:(id)sender;
在实施文件中 -ChoosePhotosViewController.m
@implementation PickPhotosViewController
@synthesize pickedImage1, pickedImage2;
对于每个按钮,我编写了一个代码,该代码调用带有操作列表的操作表:
-(IBAction)pickImage1:(id)sender {
[[NSUserDefaults standardUserDefaults] setInteger:CurrentImageCategoryImage1 forKey:@"currentImageCategory"];
[[NSUserDefaults standardUserDefaults] synchronize];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose image one" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Choose existing photo", @"Take new photo", nil];
[actionSheet showInView:self.view];
}
有两个动作 - 从库中从相机空中上传照片:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
else if (buttonIndex == 1) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
}
第二个按钮的类似算法。然后在UIImagePickerController
我写的方法中;
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
if([[NSUserDefaults standardUserDefaults] integerForKey:@"currentImageCategory"] ==CurrentImageCategoryImage1)
{
self.pickedImage1.image = chosenImage;
}
else if([[NSUserDefaults standardUserDefaults] integerForKey:@"currentImageCategory"] ==CurrentImageCategoryImage2)
{
self.pickedImage2.image = chosenImage;
}
}
然后,当我单击“下一步”按钮时,我需要在下一个 viewController 中显示这两个图像。我使用故事板,这就是我编写prepareForSegue
方法的原因:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@“next"]) {
TypeTextViewController *transferedImage = [segue destinationViewController];
transferedImage.imageWithText1 = pickedImage1;
}
}
哪里imageWithText1
是 aUIImageView
并在 中声明TypeTextViewController.h
,但是当我单击按钮时,图像不会出现在TypeTextViewController
.
哪里有问题?