Reputation: 1595
I want to use custom picker view that will add a check sign in front of selected row. I have used apple sample code for custom UIPickerView on the UICatalog example. I was able to add the check sign for a given row when creating the picker. But I failed to add it when the user rotate the wheel to select new row and also to remove it from the previously added row. Any help would be appreciated. Thanks,
Upvotes: 1
Views: 3451
Reputation: 27587
As you are not providing any code, all we can give you is a general advise;
UIPickerView
instance is inheritating the UIPickerViewDelegate
-protocoldelegate
of your UIPickerView
towards this viewController; e.g. pickerView.delegate = self;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
Upvotes: 0
Reputation: 111
1) Create subclass of UIView that will represent row in picker. Define property, for example, isChecked, which will show/hide checkmark on this view
2) In the – pickerView:didSelectRow:inComponent: call – viewForRow:forComponent: for previously selected row, set isChecked=NO
3) call – viewForRow:forComponent: for currently selected row and set isChecked=YES;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
MyCustomRowView *prevRowView = [pickerView viewForRow:currentlySelectedRow forComponent:component];
prevRowView.isChecked = NO;
MyCustomRowView *currentRowView = [pickerView viewForRow:row forComponent:component];
currentRowView.isChecked = YES;
//then save currently selected row
currentlySelectedRow = row;
}
4) you also should check currently selected row when you is requested for it:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
....
//Create or reuse view
....
rowView.isChecked = (row == currentlySelectedRow);
}
Upvotes: 3