我尝试使用自定义视图实现UIPickerView。奇怪的是,当我在选择器视图中滚动项目时,重复使用的视图总是为零。
- (UIView *)pickerView:(UIPickerView *)pickerView
viewForRow:(NSInteger)row
forComponent:(NSInteger)component
reusingView:(UIView *)view
{
UILabel* label = (UILabel *)view;
if (label==nil) {
CGRect frame = CGRectMake(0, 0, 100, 22);
label = [[UILabel alloc] initWithFrame:frame];
view = label;
}
else {
NSLog(@"This is never called");
}
label.text = [NSString stringWithFormat:@"%d",row];
return view;
}