0

Is there a way to have a UIPickerView just have escalating numbers to infinity? Haha. Just kidding, but seriously, I want just a bunch of numbers going up, but I don't want to have to hard-code it all.

Thanks in advance!

Nathan
  • 151
  • 4
  • 16

3 Answers3

9

I'm pretty sure this can be done with some cleverness (a custom integer class that supports arbitrarily large numbers, and periodically "rolling over" to a higher set of numbers once the user has scrolled through all NSIntegerMax rows (i.e. when the user scrolls to row NSIntegerMax you programmatically scroll them back to row 0 and display "row + NSIntegerMax" instead of just "row"). As they scroll through repeatedly you change it to "row + NSIntegerMax * 2", etc.

Obviously you also have to handle them changing directions are some point.

But I suspect that's what fancier than what you're looking to do. In this case you just want to add these lines of code to your View Controller:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return NSIntegerMax;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [NSString stringWithFormat:@"%d", row];
}

Then double click on the View nib file (the *.xib file) to open it in Interface Builder, and connect the "data source" outlet to the "File Owner" (the View Controller). That will get you as many integers as I could ever imagine someone scrolling to.

erich
  • 419
  • 2
  • 7
  • 11
0

You could just use a UIStepper. I know you asked about UIPicker but do you really need to use that class or were you using it to explain what kind of thing you wanted

Martin Lockett
  • 2,275
  • 27
  • 31
0

Have a look at this question. It is a variation on your problem.

Community
  • 1
  • 1
David
  • 9,635
  • 5
  • 62
  • 68
  • Sorry, I'm quite new to Objective-C, so what is numberItems and currentValue, or how do I get them? – Nathan Dec 06 '10 at 21:31
  • @Nathan, numberItems in this example is the number of items (numbers) you want to display (0-9 makes ten). Current value is the value of the current number shown. – David Dec 06 '10 at 21:55