I try to custom my pickerview to be checkable like when you click dropdownlist on webview as in the picture (youtube website).
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.