2013-07-27 21 views
0

我试图将图像从一个视图传递到另一个视图。我有一个相机按钮,当按下火焰从uiimagepickercontroller。一旦图像被选择,编辑照片屏幕被推到屏幕上。每当屏幕加载什么都不出现。我试着在这个帖子Passing image from one view to another后面,但它似乎不起作用。故事板在视图间传递图像

这里是我的第一视图控制器代码:

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]; 
} 

enter image description here

+0

如果“MYIMAGE”是的UIImageView,用它从-initWithImage删除代码: - 没有加载你的看法,所以你不能跟它。通过调试器,看看它是零。您实例化的ECDEditViewController似乎永远不会呈现。而你似乎将一个导航控制器(“composeController”)推到另一个导航控制器上,这是最奇怪的,可能是错误的。 –

+0

什么是composeController?你不想将图像传递给ECDEditViewController吗? – rdelmar

+0

@rdelmar多数民众赞成故事板ID我给了它 –

回答

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]; 
相关问题