I am writing code like
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
int n=row+1;
if(row == 0)
return [NSString stringWithFormat:@"%d minute", n];
return [NSString stringWithFormat:@"%d minutes", n];
}
now I want to start timer as I choose any row, like row 5 has 5 mints, so I want to start timer with 5 mints, so what should I do, How can I choose particular row and press button and timer starts for that event?
For the future if you go onto google and type in the name of your class and "class reference" you can usually find the information you need on the apple website.
For instance, I just went onto google and typed "UIPickerView class reference" and got to here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html.
On that website if you read the description it says "The delegate must adopt the UIPickerViewDelegate protocol" and if you click there it says, under tasks:
pickerView:didSelectRow:inComponent:
This is the delegate method you need to implement that will get called when the user selects a row. If you click on it it gives a little description and such.
If you go to the description then the full method is:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
so when a user selects a row this method is called and the pickerView is passed into the method automatically.
You can then get the row that user chose. If you go back a page to the UIPickerView class reference you see this:
– selectRow:inComponent:animated:
– selectedRowInComponent:
The method selectedRowInComponent:
is the one you want. So in the delegate method you can do something like this:
int selectedRow = (int)[pickerView selectedRowInComponent:0];
:) Thats what I do when I want to find answers to questions like this. :)
Edit:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int selectedRow = (int)[pickerView selectedRowInComponent:0];
NSLog(@"%i",selectedRow);
}