0

我正在尝试将图像从一个视图传递到另一个视图。我有一个相机按钮,按下时会触发 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];
}

在此处输入图像描述

4

1 回答 1

3

你需要做这样的事情:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

[self dismissViewControllerAnimated:YES completion:^{ 

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; 

ECDEditViewController *composeController = [self.storyboard instantiateViewControllerWithIdentifier:@"showCompose"]; 
composeController.image = image; 
[self.navigationController pushViewController:composeController animated:YES]; 

}]; 

}

您的 composeController 实际上是 ECDEditViewController,而不是 UINavigationController。所以这一行是不必要的(就像 initWithImage: 方法一样):

 ECDEditViewController *viewController = [[ECDEditViewController alloc] initWithImage:image];
于 2013-07-27T17:56:32.737 回答