我被困在这一段时间,因为它太奇怪了。我向用户提供图像选择器,并在选择时使用图像作为按钮背景。问题是它仅在第二次拾取图像后才起作用。不必是相同的图像。目前的图像选择器选择图片,没有。再次尝试相同或不同的图片,一切正常。代码如下,有没有人有任何建议?
-(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];
}
答案 0 :(得分: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];
}
答案 1 :(得分:0)
This(Is it possible to refresh a single UITableViewCell in a UITableView?)解决了这个问题!按照链接中的建议重新绘制出售。