Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think you can actually make the UIPickerView loop, but the way I've done it in the past is to return a really large number from <code>numberOfRowsInComponent</code> and then calculate the modulus of the row to return the appropriate view from <code>viewForRow</code>, like this:</p> <pre><code>// picker data source: -(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger) component { // to make it look like the picker is looping indefinetly, // we give it a really large length, and then in the picker delegate we consider // the row % (actual length) instead of just the row. return INT16_MAX; } // picker delegate: -(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger) row forComponent:(NSInteger) component reusingView:(UIView *)view { // to make it look like the picker is looping indefinetly, // we give it a really large length in the picker data source, and then we consider // the row % actual_length instead of just the row. row = row % actual_length; // where actual length is the number of options that will be looping // ... do whatever } </code></pre> <p>and in your initialization:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // ... whatever other initialization... // to make it look like the picker is looping indefinetly , // we give it a really large length in the picker data source, and then we consider // the row % actual_length instead of just the row, // and we start with the selection right in the middle, rounded to the // first multiple of actual_length so we start the selection on // the first option in the list. [myPicker selectRow:(INT16_MAX/(2*actual_length))*actual_length inComponent:0 animated:NO]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload