我有一個UIButton
,用戶點擊它來調出一個UIImagePickerController
。處理完成後,它會將已編輯的UIImage
返回給代理處理程序,然後應該使用新圖像填充UIButton
。從UIImagePickerController添加一個UIImage到一個UIButton
然而,實際上,如果用戶從他們的庫中選擇一個圖像,它會正常工作。但是,如果他們使用相機拍攝照片並對其進行編輯,則圖像不會顯示到UIButton
。但是,如果我爲了測試目的而將相同的圖像放入UIImageView
中,它就會顯示出來。
此外,這可以在模擬器中正常工作,但不適用於設備。這是一種記憶問題嗎?這裏是我的代碼:
- (IBAction)takePictureButtonTapped
{
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take a Photo", @"Upload from Library", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet:clickedButtonAtIndex:%d", buttonIndex);
if(buttonIndex == 2)
{
// cancel
[imagePickerController release];
}
else
{
imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
if (buttonIndex == 0)
{
// Take a photo
// Set up the image picker controller and add it to the view
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else if (buttonIndex == 1)
{
// Upload from Library
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == NO)
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentModalViewController:imagePickerController animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)img
editingInfo:(NSDictionary *)editInfo
{
NSLog(@"imagePickerController::didFinishPickingImage:%@", img);
itemImage = img;
[itemImage retain];
[imageButton setBackgroundImage:itemImage forState:UIControlStateNormal];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
我試過setImage
,setBackgroundImage
,所有國家,和他們沒有工作。但是,如果我將相同的圖像放入UIImageView
,那就沒有問題。
任何想法?
嘿......我爲這個問題贏得了「Tumbleweed」徽章...沒有人有任何想法嗎? – jowie 2010-08-05 22:09:10