设置新视图的UIImage并显示它

时间:2009-05-08 14:26:30

标签: iphone cocoa-touch image view uiimageview

我正在尝试设置新视图的图像。我设置控制器的图像然后显示视图。但是在控制器的viewDidLoad中,没有可用的图像。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {

EditPictureSaveViewController *editPictureController = [EditPictureSaveViewController alloc];

[editPictureController initWithNibName:@"EditPictureSaveView" bundle:[NSBundle mainBundle]];

UIImageView *imageView = [ [ UIImageView alloc ] initWithImage: image ];
[imageView setImage:image];
[editPictureController setPreview:imageView];

[self.navigationController pushViewController:editPictureController animated:YES];

1 个答案:

答案 0 :(得分:2)

那是因为

调用了viewDidLoad
[editPictureController initWithNibName:@"EditPictureSaveView" bundle:[NSBundle mainBundle]];
加载NIB后

editPictureController的image属性(我假设是UIImageView - 令人困惑!)直到此之后才设置。

在viewWillAppear:方法中执行viewDidLoad中的任何操作 - 当pushViewController:animated:调用viewWillAppear:。

时,将设置image属性。