我们可以像在UIDatePicker中那样在UIPickerView中启用行的循环吗?

时间:2009-11-24 00:58:35

标签: iphone uipickerview loops

我正在开发一个应用程序,我对UIPickerView中的行循环感到震惊。谁能帮帮我吗?如果有人发布解决方案,那将是非常有帮助的。我希望UIPickerView中的行以循环方式连续滚动,而没有终点。

3 个答案:

答案 0 :(得分:2)

有可能。对于任何需要它的人, 试试this

答案 1 :(得分:1)

我不认为这是可能的。我听说人们多次重复这些值列表,并将用户从中间某处开始。

答案 2 :(得分:0)

它确实有用,只是看内存。告知未显示的项目未存储,因此可以使列表变得庞大。如果担心,请检查分析器。 将行数设置为大数量同样容易,并使其从高值开始,用户很可能在很长一段时间内滚动滚轮 - 即便如此,最糟糕的情况是他们会触底。

(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    // Near-infinite number of rows. use NSIntegerMax, if memory problem, use less say 2000
    return 2000;
}

(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    // Row n is same as row (n modulo numberItems).
    return [NSString stringWithFormat:@"%d", row % numberItems]; // or your strings (this is for double.  numberItems is your list size.
}

(void)viewDidLoad {
    [super viewDidLoad];

    self.pickerView = [[[UIPickerView alloc] initWithFrame:CGRectZero] autorelease];
    // ...set pickerView properties... Look at Apple's UICatalog sample code for a good example.
    // Set current row to a large value (adjusted to current value if needed).
    [pickerView selectRow:3+1000 inComponent:0 animated:NO]; //pick about half the max you made earlier or about 100000 if using NSIntegerMax
    [self.view addSubview:pickerView];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    NSInteger actualRow = row % numberItems; //nb numberItems is your list size
    // ...
}

乔恩