Ios 将图像从摄影机传递到情节提要的视图

Ios 将图像从摄影机传递到情节提要的视图,ios,objective-c,storyboard,Ios,Objective C,Storyboard,我的代码有点奇怪 场景:打开相机->拍照->将拍摄的图像传递给viewcontroller(从故事板) 问题是目标视图中的我的UIimage变量不可用,无法识别 我的代码 postviewController.h #import <UIKit/UIKit.h> @interface postAlertViewController : UIViewController @property (nonatomic, retain) UIImage *cameraImage; @end

我的代码有点奇怪

场景:打开相机->拍照->将拍摄的图像传递给viewcontroller(从故事板)

问题是目标视图中的我的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];
}
stroryboard ID设置为“postview”。 我得到的是:

Property 'cameraImage' not found on object of type 'ViewController *'
为什么
cameraImage
虽然在目标的.h文件中声明,但在源视图中不可用

在另一种情况下,我需要在视图之间传递字符串,方式与上面相同

[yourViewController setValue:mysc.title forKey:@"sendAlertTitle"];
工作正常

有什么帮助吗

谢谢。

试试这个

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

并且始终使用以大写字母开头的类和接口名称

您可以更轻松地使用此名称

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

}

谢谢

您想在其他viewcontroller中显示您的图像吗?我想我已经解释过了。在View1中,按下按钮,打开相机,拍照,将图片传递给view 2。在您的情况下,secondViewController.imageview.image=firstimageview.image;:(我必须包括postviewController.h并使用postviewController*postview,而不是ViewController。很简单!谢谢!我会在可能的情况下接受。
- (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];

}