我工作的一個自定義PickerView,我在選擇器中兩個組件(小時,分鐘),我已經取得了在會議紀要「0」組成的灰色,而不是可選擇的,一切工作正常除了行被重用...我的Minutes組件在灰色字體中顯示「0」(這是我想要的),但如果您滾動選擇器,我會看到「7,14,21 .....」灰色的字體!這裏是我的代碼如何停止UIPickerView重用
enter code here
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
if(component == HOURS) {
NSString *s = [self.arrayOfHours objectAtIndex:row];
return [pickerView viewForShadedLabelWithText:s ofSize:20 forComponent:0 rightAlignedAt:52 reusingView:view];
} else if (component == MINUTES) {
NSString *s = [self.arrayOfMinutes objectAtIndex:row];
return [pickerView viewForShadedLabelWithText:s ofSize:20 forComponent:1 rightAlignedAt:52 reusingView:view];
}
else return 0;
}
- (UIView *)viewForShadedLabelWithText:(NSString *)title ofSize:(CGFloat)pointSize forComponent:(NSInteger)component rightAlignedAt:(CGFloat)offset reusingView:(UIView *)view {
//.........................
label = [self shadedLabelWithText:title ofSize:pointSize :component];
//..........................
}
- (UILabel *)shadedLabelWithText:(NSString *)label ofSize:(CGFloat)pointSize :(NSInteger)component
{
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
labelView.text = label;
if([label isEqual:@"0"] && component == 1) {
labelView.textColor = [UIColor grayColor];
}
return labelView;
}
1 - 有人可以幫我避免選擇器視圖重用行?
2 - 我如何使選擇器視圖顯示行在圓形/圓形?
您發佈的代碼包含名爲'shadedLabelWithText:ofSize ::'的方法,但您的'viewForRow:'方法調用名爲'viewForShadedLabelWithText:ofSize:forComponent:rightAlignedAt:reusingView:'的方法。 – rmaddy 2013-04-23 23:50:02
對不起,我編輯了我的問題......謝謝! – DevCali 2013-04-24 02:00:34