0

I have 3 row data in UIPickerView that is timeHour, timeMinute, timeSecond. How to collect data, show it at my labelTime after I select it from UIPickerView? I am using this code below but it only collect my first row data (timeHour).

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    labelTime.text = [timeHour objectAtIndex:[picker selectedRowInComponent:0]];
}

what I want to display in labelTime is something like this -> hh : mm : ss (let say that is 99 : 59 : 59). And how i reset it after/everytime i launch my UIPickerView back to 00 : 00 : 00?

Sorry, I am new here. thank you for your help.

Code cracker
  • 3,105
  • 6
  • 37
  • 67
Piyo
  • 181
  • 1
  • 2
  • 9

2 Answers2

0

Just write this code.

[yourPickerView reloadAllComponents];

I think it will be helpful to you.

Prasad G
  • 6,702
  • 7
  • 42
  • 65
  • im sorry, i already put it in but theres no change. everytime i call my picker, close it again and then open it again, the position is still same, doesnt reset. or else, am i put it at wrong place? any suggestion? thank you. – Piyo Jun 22 '12 at 10:04
0

actually, i always thought of the items in a picker as columns:

the function you are talking about will be called every time someone spins one of the different columns in your picker.

i would expect you'd need something like the following

NSString* hour = [timeHour objectAtIndex:[picker selectedRowInComponent:0]];
NSString* min = [timeMin objectAtIndex:[picker selectedRowInComponent:1]];
NSString* sec = [timeSec objectAtIndex:[picker selectedRowInComponent:2]];
labelTime.text = [hour stringByAppendingFormat:@":%@:%@", min, sec];  // don't forget to 0-pad if desired

as for resetting the view to 00:00:00 every time, as mentioned by prasad, outside of the delegate code you have, you can call reloadAllComponents, and then in your dataSource, have the initial values returned be all zeroes.

john.k.doe
  • 7,533
  • 2
  • 37
  • 64