我有两个 UIImageView ,每个都应该显示来自 picker 的不同图像,但我可以使用一个委托(delegate):- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info ;
这是我的代码:
- (void) importFormLibraryForCover {
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
ipc.delegate = self;
CGRect rect = CGRectMake(0 ,0, 200,660);
pop = [[ UIPopoverController alloc]initWithContentViewController:ipc];
[pop setDelegate:self];
[pop presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
[ipc release];
}
- (void) importFormLibraryForAvatar {
//same above code
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
avatarImg.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// here is the problem :
coverImg.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
问题是所有两个 imageView 都显示相同的图片,并且在 UIImagePickerController
类型的对象上找不到属性“标签”
最佳答案
您可以在 .h 文件中声明自己的枚举。
typedef enum _Type
{
eNone,
eCover,
eAvatar
}EType;
同时在.h 文件中声明一个变量EType _type;
。
在下面的方法中,
- (void) importFormLibraryForCover
{
// set variable
_type = eCover;
...
}
与其他方法类似,设置其他值。
在didFinishPickingMediaWithInfo
中,检查_type
并按要求处理。
关于iphone - 有 2 个图像选择器和 didFinishPickingMediaWithInfo 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8758709/