Setting the userInteractionEnabled
property of UILabel
to YES
fixes the highlighting issue, but it also disables the UIPickerView
from autoscrolling to select the row that has been touched.
If you want to disable the highlighting behavior, but maintain the UIPickerView
's default autoscrolling functionality, call the setShowSelection
function in the UITableCell
instances contained in the UIPickerView
. A way of doing this is to subclass the UILabel
class similar to the following:
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
Then, where you had previously been returning an instance of UILabel
in pickerView:viewForRow:forComponent:reusingView:
, return an instance of PickerViewLabel
. As an example, using the code from Doug, you would replace all the cases of 'UILabel
' with 'PickerViewLabel
'. Just remember to remove the pickerRowLabel.userInteractionEnabled = YES;
line.