为什么视图永远不会在UIPickerView中用于委托viewForRow?

时间:2014-04-11 08:14:39

标签: ios uiview uipickerview

我尝试使用自定义视图实现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;
}

0 个答案:

没有答案