2014-01-17 16 views
-1

我的代碼發生了一些奇怪的事情。從相機傳遞圖像以查看故事板

場景:!打開照相機 - >拍攝圖像 - >傳遞帶到一個視圖 - 控制圖像(從故事板

的事情是,從目標視圖我的UIImage變量不可用,無法識別

我的代碼

postviewController.h 

#import <UIKit/UIKit.h> 
@interface postAlertViewController : UIViewController 
@property (nonatomic, retain) UIImage *cameraImage; 
@end 

postviewController.m 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UIImageView *aImageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 60, self.view.frame.size.width,150)]; 
    aImageview.image=cameraImage; 
    [self.view addSubview:amageview]; 
} 

拍攝照片,並將其傳遞給視圖控制器以上

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [self dismissViewControllerAnimated:YES completion:NULL]; 
    ViewController *postView = [self.storyboard instantiateViewControllerWithIdentifier:@"postview"]; 
    postView.cameraImage=(UIImage *)[info objectForKey:UIImagePickerControllerEditedImage]; 
    [self.navigationController pushViewController:postView animated:YES]; 
} 

條痕板ID設置爲「postview」。 我所得到的是:

Property 'cameraImage' not found on object of type 'ViewController *' 

爲什麼雖然在目的地的.h文件中聲明cameraImage不能從起源的看法?

在另一種情況,其中i需要通過視圖之間的串,在與上述同樣地

[yourViewController setValue:mysc.title forKey:@"sendAlertTitle"]; 

工作確定。

任何幫助?

謝謝。

+0

? –

+0

我想我解釋過。從View1按下一個按鈕,打開攝像頭,拍攝圖片,通過圖片查看2. – Theodoros80

+0

http://stackoverflow.com/questions/20858693/access-data-variable-from-one-class-in-another-class/20858773 #20858773 –

回答

2

試試這個

postAlertViewController *postView = [self.storyboard instantiateViewControllerWithIdentifier:@"postview"]; 

和總是使用類和接口的名字開始與資本

+0

:(我不得不包含postviewController.h並使用postviewController * postview而不是ViewController。簡單!謝謝!我會盡我所能接受。 – Theodoros80

1

你可以使用更方便這一個。

- (IBAction)captureImage:(id)sender 
{ 
    if (! [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 

     UIAlertView *deviceNotFoundAlert = [[UIAlertView alloc] initWithTitle:@"No Device" message:@"Camera is not available" 
                    delegate:nil 
                  cancelButtonTitle:@"Okay" 
                  otherButtonTitles:nil]; 
     [deviceNotFoundAlert show]; 

    } else { 

     UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init]; 
     cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     cameraPicker.delegate =self; 
     // Show image picker 
     [self presentViewController:cameraPicker animated:YES completion:nil]; 
    } 
} 



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

    UIImage *selectedImage =[info objectForKey:UIImagePickerControllerOriginalImage]; 

    ViewControllerName *Vc=[self.storyboard instantiateViewControllerWithIdentifier:@"captioEdit"]; 

    Vc.postImgStr=[self scaleAndRotateImage:selectedImage]; 

    [picker dismissViewControllerAnimated:YES completion:nil]; 

    [self.navigationController pushViewController:captioViewEdit animated:YES]; 
} 

//Delegate method of UIImagePickerController for image picker model cancel 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 
    [picker dismissViewControllerAnimated:YES completion:nil]; 

} 

感謝

你想顯示一些其它視圖 - 控制內部圖像