i am trying to fill the rows of my uipickerview with content开发者_JAVA技巧 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
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
精彩评论