写真のようにウェブビューのドロップダウンリストをクリックしたときのように、ピッカービューをチェックできるようにカスタマイズしようとしています(YouTubeウェブサイト)。
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にタッチイベントメソッドを使用する必要がありますか?
助けてくれてありがとう。