任何人都可以帮助我。我正在尝试在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];
答案 0 :(得分:0)
我解决了这个问题,可以帮助陷入困境的人。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:
(NSInteger)row forComponent:(NSInteger)component
reusingView:(UIView *)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 *recognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(showTimePicker:)];
[recognizer setNumberOfTapsRequired:1];
[recognizer setDelegate:self];
if(pickerView.tag == DOORSELECTION_PICKER_TAG){
NSLog(@"its door selection category");
*[pickerView addGestureRecognizer:recognizer];*
}
}
}
不是将点击手势添加到类范围选择器视图,而是在检查标记后将手势添加到viewForRow委托方法中返回的此方法选择器视图对象。