Reputation: 15778
I want my picker view can display 1 - 200. but I think it is too much memory, if I assign an Array in this view:
self.myLargeView = [[NSArray alloc] initWithObjects:@"1 unit", @"2 units", .... ..., @"199 units" @"200 units", nil]; //code skipped
How can I reduce the memory load in application? any ideas?
Upvotes: 0
Views: 331
Reputation: 14235
If you want your picker view just to display an incremented number then you might use something like this:
#define kPickerValuesAmount 200
#pragma mark -
#pragma mark UIPickerViewDataSource methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return kPickerValuesAmount;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [NSString stringWithFormat:@"%i unit%@", (row + 1), (row == 0 ? @"" : @"s")];
}
Upvotes: 3
Reputation: 135558
An array of 200 short NSStrings will not cause you any memory problems. It just takes up a few kilobytes.
Upvotes: 0
Reputation:
If the user has to just pick a number from 1 to 200, why not use a UISlider instead?
Upvotes: 0