0

我的问题是,当我尝试识别 uipickerview 的文本字段的内容并尝试检查选项哪个内容等于文本字段的内容时,如果选项超过三个选项并且所选选项是第四个或复选标记之后不是创建并没有检查任何内容。我做了一个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;

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

4

0 回答 0