The most efficient way to populate a select view with a range of integers?

I have a simple user interface selector in an iOS application (iPhone), and I want to pre-populate it with a number of numbers at startup. What would be the most pragmatic / fast / optimized way to populate it? I am new to iOS development, so I'm just starting to test the waters. The documentation is pretty decent, but I would like to get an idea from experienced developers about the most efficient way to accomplish what I'm doing?

TL; dg

I want to fill out a UI selection view with a range of numbers 45-550 at the beginning of my application, what is the best way to do this?

+3
source share
1 answer

Despite the fact that I can not qualify as an experienced developer, I would do it like this. In the class that will be the data source and delegate of the selection view:

#define PICKER_MIN 45
#define PICKER_MAX 550

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return (PICKER_MAX-PICKER_MIN+1);
}

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

Source: https://habr.com/ru/post/1771405/


All Articles