views:

40

answers:

1

Hi everyone, i am trying to fill the rows of my uipickerview with content and i'm trying to do it like this:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *test;

for (int i; i<5; i++) {
        if (row == i) {
            test = [NSString stringWithFormat:@"%i", i];
            return test;
        }


}

return @"";

}

But it doesn't display all of the numbers and sometimes they even disappear.... What am i doing wrong? i don't want to have to fill all of the rows manually because i am going to fill this pickerview with minutes and seconds which would make this a view with 60 rows..... Any help is greatly appreceated! Thanks

A: 

Just return the string you want to appear in a row:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
                                         forComponent:(NSInteger)component {

    return [NSString stringWithFormat:@"%d", row];
}

UIPicker will call this delegate method only when the row is about to display.

P.S. Have a look at UIDatePicker - may be it already does what you want

Vladimir
Unfortunately the UIDatePicker can only display hours and minutes instead of seconds and minutes and i wouldn't know how to change that..
Christoph v