Get selected row in UIPickerView for each component
Swift 3 version:
var value = ""
for i in 0..<numberOfComponents {
let selectedRow = pickerView.selectedRow(inComponent: i)
if let s = pickerView.delegate?.pickerView!(pickerView, titleForRow: selectedRow, forComponent: i) {
value += s
}
}
So, in your button action method, you can do something like this:
- (IBAction) showAlert {
NSUInteger numComponents = [[myPickerView datasource] numberOfComponentsInPickerView:myPickerView];
NSMutableString * text = [NSMutableString string];
for(NSUInteger i = 0; i < numComponents; ++i) {
NSUInteger selectedRow = [myPickerView selectedRowInComponent:i];
NSString * title = [[myPickerView delegate] pickerView:myPickerView titleForRow:selectedRow forComponent:i];
[text appendFormat:@"Selected item \"%@\" in component %lu\n", title, i];
}
NSLog(@"%@", text);
}
This would be the absolute formal way to retrieve information (by using the proper datasource and delegate methods), but it might be easier (depending on your set up), to just grab the selected row and then pull the information out of your model directly, instead of going through the delegate method.