1

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

助けてくれてありがとう。

4

2 に答える 2

1

はい、タッチ イベントを使用する必要があります。ただし、標準の UIPickerView はタッチをキャプチャして転送しないため、viewcontroller はイベントを受け取りません。

タッチでエスケープできるようにする UIPickerView サブクラスを使用して、Github にプロジェクトを作成しました。それらをスーパービューに転送し、viewcontroller の touchesEnded メソッドで選択を処理します。また、前述のチェックマークも実装しています。

于 2011-08-13T15:17:18.270 に答える
0

これを参照してください: https://github.com/scelis/SCKit/tree/

サンプルプロジェクトがあります。ここにコードを貼り付けるよりもはるかに優れています。

于 2012-02-18T12:22:47.663 に答える