0

あるビューから別のビューに画像を渡そうとしています。カメラボタンがあり、押すとuiimagepickercontrollerが起動します。画像を選択すると、写真の編集画面が画面に表示されます。画面が読み込まれるたびに何も表示されません。この投稿Passing image from one view to anotherに従ってみましたが、うまくいかないようです。

最初のView Controllerのコードは次のとおりです。

firstViewController.h

@interface firstViewController : UITableViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate>

- (IBAction)cameraButtonPressed:(id)sender;

firstViewController.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 に答える