English 中文(简体)
Can we enable looping of rows in a UIPickerView as we do it in UIDatePicker? [duplicate]
原标题:

I am developing an App where i am struck with the looping of rows in a UIPickerView. Can anyone please help me? it would be of great help if anyone would post the solution. I want the rows in a UIPickerView scroll continuosly in a circular manner without having a end point.

最佳回答

It is possible. For anyone of you who needs it, try this.

问题回答

I don t think it s possible. I ve heard of people repeating the list of values a large number of times, and starting the user off somewhere in the middle.

It does work, just watch the memory. Told that items not shown are not stored so can make list huge. Check with profiler if worried. It s just as easy to set the number of rows to a large number, and make it start at a high value, there s little chance that the user will ever scroll the wheel for a very long time -- And even then, the worse that will happen is that they ll hit the bottom.

(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
    // ...
}

Jon





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签