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.
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.