我真的在苦苦挣扎,也许是因为我是Objective-C的新手,能够执行以下操作。
问题: 1.它不会显示下一个控制器 2.它不会改变imageView来保存我选择的图片
观察: 1.当我在控制器1上使用imageView而不是2时,它就像我想要的那样保持图像 2.调试器显示调用控制器2类中更改imageView的函数。但是,即使我试图简单地更改标签,也没有任何变化。
代码: MAViewControllerMenu.h
@interface MAViewControllerMenu : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
UIImagePickerController *picker1;
UIImagePickerController *picker2;
UIImage *image;
IBOutlet UIImageView *imageView;//THIS CHANGES,BUT IS IN CONTROLLER 1
}
- (IBAction)TakePhoto;
- (IBAction)ChooseExisting;
- (IBAction)movetonext;
MAViewControllerPictureDisplay.h
#import "MAViewControllerMenu.h"
@interface MAViewControllerPictureDisplay : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate,menuControllerDelegate>
{
}
@property (weak, nonatomic) IBOutlet UIImageView *bigImageView;//THIS ONE WOULDNT HOLD THE CHOSEN IMAGE
@property (weak, nonatomic) IBOutlet UILabel *theLabel;
@property(nonatomic, strong) UIImage *image;
@end
实施
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//load next page
self.bigImageView.image = self.image;
}
在MAViewControllerMenu.m
中对图片选择做出反应的方法#import "MAViewControllerMenu.h"
#import "MAViewControllerPictureDisplay.h"
@interface MAViewControllerMenu ()
@end
@implementation MAViewControllerMenu
MAViewControllerPictureDisplay* imageControllerView;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image]; //WORKS ON CURRENT CONTROLLER
//imageControllerView.theLabel.text = @"hhdhdhd"; //DIDNT WORK
[imageControllerView.bigImageView setImage:image]; //UPDATE IMAGE AT CONTROLLER 2, DIDNT WORK
[self dismissViewControllerAnimated:YES completion:NULL];
[self movetonext];
}
- (IBAction)movetonext{
[self presentViewController:imageControllerView animated:YES completion:nil];//MOVE TO NEXT WINDOW- DOESNT WORK WHEN INVOKED AFTER SELECTING A PICTURE. DOES WORK WHEN INVOKING,SAY, AFTER A BUTTON WAS CLICKED
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//load next page
imageControllerView = [[self storyboard] instantiateViewControllerWithIdentifier:@"chosenImageController"];
}
答案 0 :(得分:0)
图片未显示在第二个视图控制器中,因为此时您正在设置图像的图像视图尚不存在。
[imageControllerView.bigImageView setImage:image];
声明UIImage
property
并使用它传递图像。然后在imageControllerView
的{{1}}中显示viewDidLoad
。例如:
UIImageView
答案 1 :(得分:0)
不要那样做。您应该将另一个视图控制器的视图视为私有。 Reecon显示了执行此操作的正确方法(设置属性以保存信息,然后在viewDidLoad或vieWillAppear:animated中显示该信息)