【发布时间】:2023-04-01 18:25:01
【问题描述】:
谁能帮帮我。我正在尝试在 UIPickerview(在 iOS 7 中)上实现多项选择。由于堆栈溢出的引用很少,我做了如下,
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UITableViewCell *cell = (UITableViewCell *)view;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell setBackgroundColor:[UIColor clearColor]];
[cell setBounds: CGRectMake(0, 0, cell.frame.size.width -20 , 44)];
cell.tag = row;
cell.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleSelection:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
singleTapGestureRecognizer.delegate= self;
[cell addGestureRecognizer:singleTapGestureRecognizer];
[self.doorSelectionPickerView addGestureRecognizer:singleTapGestureRecognizer];
}
//TO DO FOR CHECKMARK
cell.textLabel.text = @"1";
return cell;
}
尝试后,它没有收到点击手势,因此toggleSelection方法没有被调用。
注意:UIpickerview 是作为 UITextField 的输入视图给出的
userSafeDoorTextfeild.inputView = [self doorSelectionPickerView];
【问题讨论】:
标签: iphone ios7 uipickerview