如何从与uipickerview相关的文本字段的内容中识别并检查uipickerview中的选定选项

时间:2013-05-21 14:59:18

标签: iphone uipickerview

我的问题是,当我尝试识别uipickerview的文本字段的内容时,我尝试检查选项哪个内容等于textfield的内容,如果选项超过三个选项而选择的选项是第四个或之后未创建复选标记,未选中任何内容。 我做了一个pickercell类(uiview包含复选标记)来确定选择了哪个选项。在实现uipickerview的委托并生成ui的类中,我这样做是为了检查所选的选项:

for (int i = 0; i < [self.customPickerView numberOfRowsInComponent:0]; i++)
{
    PickerViewCell *label = (PickerViewCell *)[self.customPickerView viewForRow:i forComponent:0];
    for (int j = 0; j < [self.selectedItems count]; j++) {
        if ([(NSString *)[self.selectedItems objectAtIndex:j]
             isEqualToString:(NSString *)[self.options objectAtIndex:i]]) {
            label.checkMarkView.hidden = NO;
        }
    }    
}

在pickerview委托中我做了这个:

PickerViewCell *label = (PickerViewCell *)view;
    self.customPickerView.showsSelectionIndicator   = NO;
    // Add a gesture recognizer to detect taps in pickerview
    UITapGestureRecognizer *MultipleTap = [[UITapGestureRecognizer alloc]
                                            initWithTarget:self
                                                    action:@selector(tapMultipleInPickerView:)];
    [MultipleTap setNumberOfTapsRequired:1];
    //[singleTap setNumberOfTouchesRequired:1];
    [self.customPickerView addGestureRecognizer:MultipleTap];
    if (!label)
    {
        // Customize your label (or any other type UIView) here
        label = [[PickerViewCell alloc]
                 initWithFrame:CGRectMake(0.0f, 0.0f, self.customPickerView.bounds.size.width * 0.8, 44.0f)];
    }
    if (row < [self.options count])
    {
        label.label.text = (NSString *)[self.options objectAtIndex:row];
        //label.checkMarkView.hidden = !(row == self.currentOption);
    }
    return label;

任何帮助将不胜感激。感谢。

0 个答案:

没有答案