我尝试将我的选择器视图自定义为可检查的,就像您在图片(youtube 网站)中单击 webview 上的下拉列表时一样。
http://img830.imageshack.us/img830/3747/screenshot20101004at606.png
我使用 viewForRow 方法为选择器中的每一行自定义视图。
- (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];
}
当我选择我想要的行时,它会完美地为所选行添加复选标记但是当我向上/向下滚动选择器时,选择器将自动选择选择器中间的行。因此,它会在中间行自动添加复选标记。
我的问题是如何禁用中间行的自动选择。当用户在他们想要的行上标签时,它应该添加复选标记(如在 youtube 中)。
我应该对pickerview使用触摸事件方法吗?
谢谢您的帮助。