Iphone / Objective-c将图像和文本加载到双选择器中

时间:2012-03-30 17:28:56

标签: iphone objective-c uiimage picker

我一直试图让双重选择器同时显示文字和图像。左选择器将有文本,右边将有图像。当我做文本时,它工作正常,但当我尝试使图像出现时,我得到一个错误说 0x6b8b230> setValue:forUndefinedKey:]:此类不是键列1的键值编码兼容。 到目前为止,我得到了这个,但我卡住了,不知道该怎么做。

@property (strong, nonatomic) NSArray *textvals;
@property (strong, nonatomic) NSArray *imagevals;
@synthesize textvals;
@synthesize imagevals;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSArray *totalArray = [[NSArray alloc] initWithObjects:@"Text 1",
                             @"text2", @"text 3", @"text 4", nil];
    self.textvals = totaltextArray;
    UIImage *image1 = [UIImage imageNamed:@"first.png"];
    UIImage *image2 = [UIImage imageNamed:@"second.png"];
    UIImage *image3 = [UIImage imageNamed:@"third.png"];
    UIImage *image4 = [UIImage imageNamed:@"fourth.png"];
    UIImageView *image1View = [[UIImageView alloc] initWithImage:image1];
    UIImageView *image2View = [[UIImageView alloc] initWithImage:image2];
    UIImageView *image3View = [[UIImageView alloc] initWithImage:image3];
    UIImageView *image4View = [[UIImageView alloc] initWithImage:image4];
    NSArray *totalimagearray = [[NSArray alloc] initWithObjects:image1View, image2View, image3View, image4View,nil];
    //[self setValue:totalimagearray forKey:"1"];
    self.imagevals = totalimagearray;
}

1 个答案:

答案 0 :(得分:1)

是的,绝对有可能。你需要处理pickerView委托方法

  • (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)行        forComponent:(NSInteger)组件重用View:(UIView *)视图

这里你只需返回自定义视图(可以是任何UIImage UILabel)

并将userInteractionEnable属性设置为no以进行自定义视图..