1

I try to custom my pickerview to be checkable like when you click dropdownlist on webview as in the picture (youtube website).

enter image description here http://img830.imageshack.us/img830/3747/screenshot20101004at606.png

I use viewForRow method to customize view for each row in picker.

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

 UIView *rowView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)] autorelease];
 rowView.backgroundColor = [UIColor clearColor];
 rowView.userInteractionEnabled = NO;

 UIImageView *checkmarkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 24, 19)];

 UIFont *font = [ UIFont boldSystemFontOfSize:18];
 UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 0, 240, 44) ];
 NSString *pickerText = [[Itemlist objectAtIndex:row] objectForKey:@"name"];
 titleLabel.text = pickerText;
 titleLabel.textAlignment = UITextAlignmentLeft;
 titleLabel.backgroundColor = [UIColor clearColor];
 titleLabel.font = font;
 titleLabel.opaque = NO;

 if ([selected_property_id intValue] == row) {
  titleLabel.textColor = [UIColor blueColor];
  checkmarkImageView.image = [UIImage imageNamed:@"checkmark.png"];
 }else {
  titleLabel.textColor = [UIColor blackColor];
  checkmarkImageView.image = nil;
 }

 [rowView addSubview:checkmarkImageView];
 [rowView addSubview:titleLabel];
 [titleLabel release];
 [checkmarkImageView release];

 return rowView; 

}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
 [m_pickerView reloadAllComponents];
}

When I select the row that I want, it add checkmark to the selected row perfectly BUT when I scroll picker up/down the picker will auto select the row at the middle of picker. So, it auto add checkmark in the middle row.

My question is how to disable auto select on the middle row. It should add checkmark when user tab on the row that they want only (like in youtube).

Should I use touch event method for pickerview?

Thanks for the help.

Sam
  • 1,509
  • 3
  • 19
  • 28
Dolly
  • 81
  • 2
  • 8
  • If you would like the `UIPickerView` to display the checkmarks for you, please [file a bug](http://bugreport.apple.com) request this feature. – Dave DeLong Aug 13 '11 at 15:23

2 Answers2

1

Yes, you should use touch events. However, the standard UIPickerView captures touches and won't forward them, so the viewcontroller never receives the events.

I've created a project on Github with a UIPickerView subclass that does allow touches to escape it. It forwards them to its superview and then handles selection in the viewcontroller's touchesEnded method. It also implements the mentioned checkmark.

Thor Frølich
  • 664
  • 5
  • 18
0

Reference this: https://github.com/scelis/SCKit/tree/

It have a example project. really better then code paste here.

Jiejing Zhang
  • 1,030
  • 8
  • 16