I know the UIPickerView has this method:
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
But inside this method, I want to get the selected row of other components. How on Earth can I do that?
You can get selected row number anywhere by using selectedRowInComponent method of UIPickerView
.
Such like
NSString *YourselectedTitle = [self.yourArrayName objectAtIndex:[self.yourPickerName selectedRowInComponent:0]];
NSLog(@"%@", YourselectedTitle);
Old question but if someone like me is working with Swift 2.0 now the answer is
let row = self.myPicker.selectedRowInComponent(0)
let value = myArray[row]
I wrote 0 to component value because my picker has only one component, but it could have more than one such as datepicker with Date and Time
You can even use this method outside the function that you were talking about if you keep an outlet of your pickerview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With