我正在尝试将图像从一个视图传递到另一个视图。我有一个相机按钮,按下时会触发 uiimagepickercontroller。选择图像后,编辑照片屏幕将被推送到屏幕上。每当屏幕加载时,什么都不会出现。我尝试关注这篇文章将图像从一个视图传递到另一个视图,但它似乎不起作用。
这是我的第一个视图控制器的代码:
第一视图控制器.h
@interface firstViewController : UITableViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate>
- (IBAction)cameraButtonPressed:(id)sender;
第一视图控制器.m
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:^{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
ECDEditViewController *viewController = [[ECDEditViewController alloc] initWithImage:image];
UINavigationController *composeController = [self.storyboard instantiateViewControllerWithIdentifier:@"showCompose"];
//[self.navigationController presentViewController:composeController animated:YES completion:nil];
[self.navigationController pushViewController:composeController animated:YES];
}];
}
secondViewController.h
@interface ECDEditViewController : UITableViewController <UIImagePickerControllerDelegate>
- (id)initWithImage:(UIImage *)aImage;
@property (strong, nonatomic) IBOutlet UIImageView *myImage;
@property (nonatomic, strong) UIImage *image;
secondViewController.m
@implementation ECDEditViewController
@synthesize myImage;
@synthesize image;
- (id)initWithImage:(UIImage *)aImage {
self = [super init];
if (self) {
if (!aImage) {
NSLog(@"sorry no picture loaded®");
return nil;
}
self.image = aImage;
[myImage setImage:aImage];
NSLog(@"picture loaded");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"im trying");
[myImage setImage:image];
[myImage setContentMode:UIViewContentModeScaleAspectFit];
}