I have a ViewController with the fallowing viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
model = [GlobalDataModel sharedDataModel];
programTypes = @[@"Gewichtsreduktion", @"Verdauungs-/Stoffwechselprobleme", @"Energielosigkeit, Müdigkeit",
@"Stress, Burn-out", @"Unruhe, Schlaflosigkeit", @"Immunsystem, Hautprobleme", @"Sport - Muskelaufbau", @"Sport - Ausdauersport", @"Sport - Leistungssport"];
int row = 8; //[model.infoDictionary[@"programmtyp"] intValue];
[programTypePicker selectRow:row inComponent:0 animated:NO];
}
and this delegate-methods for the UIPickerView:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return programTypes.count;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
return programTypes[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
model.infoDictionary[@"programmtyp"] = [NSString stringWithFormat:@"%ld",(long)row];
}
The problem is, that in the viewDidLoad, when I set row = 8 it will always select not the last row - instead the second-last row (instead of "Sport - Leistungssport" it select "Sport - Ausdauersport"). When I use a row smaller then 8 it will work correctly.
Does somone can help me, what I am doing wrong? - Thank you.