0

我被困了一段时间,因为它太奇怪了。我向用户展示了图像选择器,并在选择时使用图像作为按钮背景。问题是它仅在第二次选择图像后才起作用。不必是相同的图像。当前图像选择器选择图片,什么都没有。再次尝试相同或不同的图片,一切正常。代码如下,有人有什么建议吗?

-(void) changeProfileImage:(UIImage*) image {
    profilePhoto = image;

    [editPhotoButton setTitle:@"edit" forState:UIControlStateNormal];
    [editPhotoButton setBackgroundImage:profilePhoto forState:UIControlStateNormal];
    [editPhotoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];    
}

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *) imageInfo {
    UIImage* imageToUse;
    UIImage* editedTmpImage = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
    if (!editedTmpImage)
       imageToUse = [imageInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
       imageToUse = [imageToUse resizedImageWithContentMode:UIViewContentModeScaleAspectFill bounds:CGSizeMake(MIN(imageToUse.size.width,1024), MIN(imageToUse.size.width, 768)) interpolationQuality:kCGInterpolationHigh];

   [self changeProfileImage:imageToUse];
   [imagePicker dismissViewControllerAnimated:YES completion:Nil];
}
4

2 回答 2

0

是否可以在 UITableView 中刷新单个 UITableViewCell?)解决了问题!按照链接中的建议重新绘制销售。

于 2013-09-15T01:52:52.730 回答
0

首先,只是为了确保,你能像这样把它清理一下,然后再试一次吗?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *) imageInfo {
    UIImage* imageToUse = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
    if (!imageToUse) { // this part was confusing above, please use curvy-braces
       imageToUse = [imageInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
    }
    imageToUse = [imageToUse resizedImageWithContentMode:UIViewContentModeScaleAspectFill bounds:CGSizeMake(MIN(imageToUse.size.width,1024), MIN(imageToUse.size.width, 768)) interpolationQuality:kCGInterpolationHigh];

    [self changeProfileImage:imageToUse];
    [imagePicker dismissViewControllerAnimated:YES completion:nil];
}
于 2013-09-14T21:19:59.297 回答