我的代码发生了一些奇怪的事情。
场景:打开相机 - >拍照 - >将拍摄的图像传递给视图控制器(来自故事板。
问题是我的目标视图中的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];
}
stroryboard ID设置为“postview”。 我得到的是:
Property 'cameraImage' not found on object of type 'ViewController *'
为什么cameraImage
在原点视图中不可用,尽管在目标的.h文件中声明了?
在另一种情况下,我需要在视图之间传递字符串,方式与上面相同
[yourViewController setValue:mysc.title forKey:@"sendAlertTitle"];
工作正常。
任何帮助?
谢谢。
答案 0 :(得分:2)
试试这个
postAlertViewController *postView = [self.storyboard instantiateViewControllerWithIdentifier:@"postview"];
并始终使用类和接口名称以大写
开头答案 1 :(得分: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];
}
由于