I know that with a UIDatePicker, you can use something like:
NSDate *myDate = picker.date;
But I am using a UIPickerView in my view. How c
You have to use the didSelectRow
delegate method, because a UIPickerView
can have an arbitrary number of components. There is no "objectValue" or anything like that, because that's entirely up to you.
NSInteger SelectedRow;
SelectedRow = [yourPickerView selectedRowInComponent:0];
selectedPickerString = [YourPickerArray objectAtIndex:SelectedRow];
self.YourTextField.text= selectedPickerString;
// if you want to move pickerview to selected row then
for (int i = 0; I<YourPickerArray.count; i++) {
if ([[YourPickerArray objectAtIndex:i] isEqualToString:self.YourTextField.text]) {
[yourPickerView selectRow:i inComponent:0 animated:NO];
}
}
This is my answer
- (IBAction)Result:(id)sender
{
self.statusLabel.text = DataSource[[pickerViewTool selectedRowInComponent:0]];
}
This is what I did:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
selectedEntry = [allEntries objectAtIndex:row];
}
The selectedEntry
is a NSString
and will hold the currently selected entry in the pickerview. I am new to objective C but I think this is much easier.
You will need to ask the picker's delegate, in the same way your application does. Here is how I do it from within my UIPickerViewDelegate:
func selectedRowValue(picker : UIPickerView, ic : Int) -> String {
//Row Index
let ir = picker.selectedRow(inComponent: ic);
//Value
let val = self.pickerView(picker,
titleForRow: ir,
forComponent: ic);
return val!;
}
Getting the selected title of a picker:
let component = 0
let row = picker.selectedRow(inComponent: component)
let title = picker.delegate?.pickerView?(picker, titleForRow: row, forComponent: component)