imagePickerController设置UIImageView.image不会更改显示的图像

时间:2014-10-20 16:29:54

标签: ios objective-c uiimageview uiimage uiimagepickercontroller

我正在尝试将UIImageView的图像设置为下面的UIImagePickerController的返回。我的UIImageView profileImageView在viewdidload中实例化。奇怪的是,UIImagePickerController返回的图像尚未显示在profileImageView中。最初我认为这是图像问题,所以我把它修改为SR-rewards.jpg。添加NSLog,它显示[profileImageView setImage:[UIImage imageNamed:@" SR-rewards.jpg"]]已执行,但profileImageView.image.size.height为0。 然后我用 [profileImageView performSelectorOnMainThread:@selector(setImage:) withObject: [UIImage imageNamed:@"SR-rewards.jpg"] waitUntilDone:YES];给它另一个镜头 在主线程中运行它。虽然,图像仍未显示,但profileImageView.image.size.height更改为277。

有什么想法吗?我该如何设置图像?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    [profileImageView setImage:[UIImage imageNamed:@"SR-rewards.jpg"]];//[self cropImage:smallImage];
    NSLog(@"%f" , profileImageView.image.size.height);
    [picker dismissViewControllerAnimated:YES completion:NULL];

}

此致 锤

1 个答案:

答案 0 :(得分:7)

更新主队列中的UI。

dispatch_async(dispatch_get_main_queue(), ^{
    [profileImageView setImage:[UIImage imageNamed:@"SR-rewards.jpg"]];
});