userInteractionEnabled
のプロパティをUILabel
に設定するYES
と、強調表示の問題が修正さUIPickerView
れますが、タッチされた行を選択するための自動スクロールも無効になります。
ハイライト動作を無効にするが、 のデフォルトの自動スクロール機能を維持する場合は、 に含まれるインスタンスで関数UIPickerView
を呼び出します。これを行う方法は、次のようなクラスをサブクラス化することです。setShowSelection
UITableCell
UIPickerView
UILabel
PickerViewLabel.h -
#import <UIKit/UIKit.h>
@interface PickerViewLabel:UILabel
{
}
@end
PickerViewLabel.m -
#import "PickerViewLabel.h"
@implementation PickerViewLabel
- (void)didMoveToSuperview
{
if ([[self superview] respondsToSelector:@selector(setShowSelection:)])
{
[[self superview] performSelector:@selector(setShowSelection:) withObject:NO];
}
}
@end
次に、以前にUILabel
inのインスタンスを返していた場所にpickerView:viewForRow:forComponent:reusingView:
、 のインスタンスを返しますPickerViewLabel
。例として、 Dougのコードを使用すると、' 'のすべてのケースを ' UILabel
'に置き換えますPickerViewLabel
。行を削除することを忘れないでpickerRowLabel.userInteractionEnabled = YES;
ください。