这一点可以比较容易地利用带有习俗成分观点的选子来实现。 利用实例变量跟踪你选定的行文,并相应改变你的标识。 如果你想要列入检查标记,那么你需要走一步,使用“IDView”的门槛,而不是简单的“IDLabel”。
@interface ViewContainingPicker
{
NSUInteger mySelectedRow;
}
@end
@implementation ViewContainingPicker
// Init, Picker setup, etc
- (UIPickerView *)myPickerView
{
// Create picker, set mySelectedRow to NSNotFound
mySelectedRow = NSNotFound;
return myPickerView;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = (UILabel *)view;
if (nil == label) {
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, PICKER_WIDTH, PICKER_ROW_HEIGHT)] autorelease];
}
label.text = @"Label for this row";
// Selected Row will be blue
if (row == mySelectedRow) {
label.textColor = [UIColor blueColor];
} else {
label.textColor = [UIColor blackColor];
}
return label;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Just set selected component and reload, color will change in dataSource pickerView:viewForRow:forComponent:reusingView:
mySelectedRow = row;
[pickerView reloadComponent:component];
}