Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's possible. Here is how you can do it. First setup a timer. Let's assume <code>int maxNumber</code> is an instance variable set to some arbitrary value.</p> <pre><code>- ( void) viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.timer invalidate]; self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES]; } - (void) viewWillDisappear:(BOOL)animated{ [self.timer invalidate]; [super viewWillDisappear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self.infinitePickerView selectRow:(int)maxNumber*5 inComponent:0 animated:YES]; } </code></pre> <p>In the timer fire method check if any of the 'edge' view of your uipickerview are showing.</p> <pre><code>- (void)timerFireMethod:(NSTimer*)theTimer{ int rowSelected = [self.infinitePickerView selectedRowInComponent:0]; for (int i=0; i&lt;= 20; i++) { UIView * viewBelow = [self.infinitePickerView viewForRow:i forComponent:0]; UIView * viewAbove = [self.infinitePickerView viewForRow:maxNumber*10-20+i forComponent:0]; if(viewBelow!=nil || viewAbove!=nil){ int middlePosition = maxNumber * 5 + (rowSelected % maxNumber); [self.infinitePickerView selectRow:middlePosition inComponent:0 animated:NO]; break; } } } </code></pre> <p>Note this works because <code>[self.infinitePickerView viewForRow:i forComponent:0];</code> returns a UIView only if it's visible.</p> <p>Of course your <code>UIPickerViewDelegate</code> must use be something like</p> <pre><code>- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return maxNumber * 10; //returning a large number } //You cannot use this method /* - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{} You have to use the method below in lieu of it */ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel * label; if (!view) { label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.infinitePickerView.bounds.size.width, 30)]; }else { label = (UILabel *) view; } [label setText:[NSString stringWithFormat:@" %d", row % maxNumber]]; return label; } </code></pre> <p>Hope this works!! :) Good luck!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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