无法重置UIImageView

时间:2013-02-13 06:18:58

标签: objective-c xcode uiimageview uiimagepickercontroller

我正在开发一个iOS应用程序,允许用户从库中选择一个图像(UIImagePicker),并在不同视图控制器中的UIImageView中显示图像。

在我的cameraViewController.m中,当调用didFinishPickingMediaWithInfo时,它会在UploadView中调用setImageNow方法。

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    [picker dismissModalViewControllerAnimated:YES];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = [info
                      objectForKey:UIImagePickerControllerOriginalImage];

        imageView = [[UIImageView alloc]initWithImage:image];

        **UploadView *myUploadViewController = [[UploadView alloc]init];
        [myUploadViewController setImageNow:imageView.image];**
    }
}

在我的UploadView.m中,

- (void)setImageNow:(UIImage*)image{
    NSLog(@"yy: %@",image);
    if(image != nil){
        [selectedImageView setImage:image];
        NSLog(@"xx: %@",selectedImageView.image);
        }
}

xx和yy的NSLog值是相同的,所以我认为已验证selectedImageView被更改为用户选择的新图像。但是,在用户界面中,不显示新图像。默认图像仍然存在。加载视图时,有一个默认图像设置为selectedImageView,代码在此处:

- (id)initWithFrame:(CGRect)frame {
    if (!(self = [super initWithFrame:frame]))
        return nil;
    NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"UploadView" owner:self options:nil];
    UIView* myView = [nibViews objectAtIndex: 0];
    [super addSubview:myView];
    return self;
}

我尝试了不同的方法来解决问题,但没有一种方法可行。有谁知道我的代码有什么问题?谢谢!

0 个答案:

没有答案