2013-08-12 2 views
0

지금까지 이것이 내 코드입니다. 사진 갤러리에서 사진을 선택하여 하나의 컨트롤러에서 이미지보기로 표시 할 수 있습니다.보기 컨트롤러에는 다음 뷰 컨트롤러로 보내지는 단추가있는 단추가 있습니다. 이보기 컨트롤러는 다른 이미지보기입니다.사진 라이브러리에서 가져온 uiimageview에서 다른보기 컨트롤러의 다른 uiimageview로 가져온 이미지를 표시하는 방법은 무엇입니까?

첫 번째 컨트롤러의 이미지보기를 두 번째보기 컨트롤러의 두 번째 이미지보기에 표시하려면이 코드는 지금까지의 코드입니다.

조치를 취하는 데 도움이되도록 조치를 취해야할지 잘 모르겠지만 여러 가지 시도를 해봤지만 제대로 수행하지 못하고 있다고 생각하므로 깨끗하게 보냅니다. 슬레이트와 몇 가지 조언

을 얻을 Viewcontroller.h는

#import <UIKit/UIKit.h> 


@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> 
@property (weak, nonatomic) IBOutlet UIImageView *imageView; 
@property (strong, nonatomic) UIImage *chosenImage; 

@property(strong, nonatomic) UIImagePickerController *imagePicker; 


@end 

Viewcontroller.m

#import "ViewController.h" 


@interface ViewController() 

@end 


@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSString *myGrabbedImage = @"myGrabbedImage.png"; 
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES); 
    NSString *documentDirectory = [path objectAtIndex:0]; 
    NSString *fullPath = [documentDirectory stringByAppendingPathComponent:myGrabbedImage]; 
    NSData *data = [NSData dataWithContentsOfFile:fullPath]; 
    [[self imageView]setImage:[UIImage imageWithData:data]]; 
} 
- (IBAction)chooseImage:(id)sender 
{ 
    self.imagePicker = [[UIImagePickerController alloc]init]; 
    self.imagePicker.delegate = self; 
    [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 
    [self presentViewController:self.imagePicker animated:YES completion:nil]; 
} 

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    self.chosenImage = info[UIImagePickerControllerOriginalImage]; 

    NSData *data = UIImagePNGRepresentation(self.chosenImage); 
    NSString *myGrabbedImage = @"myGrabbedImage.png"; 
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentDirectory = [path objectAtIndex:0]; 

    [self.imageView setImage:self.chosenImage]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    NSString *fullPathToFile = [documentDirectory stringByAppendingPathComponent:myGrabbedImage]; 
    [data writeToFile:fullPathToFile atomically:YES]; 


} 


- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 

} 




@end 

답변

0

는 두 번째 ViewControll에 UIImage 속성을 만들기 어과를 통해 이미지를 전달 prepareForSegue

다음 두 번째의 ViewController에 설정할 수있는

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 

    if ([[segue identifier] isEqualToString:@"yourSegueIdentifier"]) { 
     yourSecondViewController *secondVC = [segue destinationViewController]; 
     secondVC.nextImage = self.chosenImage; 
    } 

} 

을 이미지 뷰

yourSecondImageView.image = nextImage; 
을 (두 번째의 ViewController 그래서 ViewController 그것에 대해 알고 가져 잊지 마세요)
관련 문제