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 can i similarly get the value selected? Or do I have to setup didSelectRow type of method to do this?
Update: This code works for picker with 1 component:
NSInteger row;
NSString *weightSelected;
row = [repPicker selectedRowInComponent:0];
weightSelected = [pickerArray objectAtIndex:row];
I tired this code for my picker with 2 components, but it is freezing:
NSInteger row1, row2;
NSString *weightSelected1;
NSString *weightSelected2;
row1 = [repPicker selectedRowInComponent:0];
row2 = [repPicker selectedRowInComponent:1];
weightSelected1 = [pickerArray objectAtIndex:row1];
weightSelected2 = [pickerArray objectAtIndex:row2];
NSString *weightSelected = [NSString stringWithFormat:@"%@.%@", weightSelected1, weightSelected2];
You can get it in the following manner:
NSInteger row;
NSArray *repeatPickerData;
UIPickerView *repeatPickerView;
row = [repeatPickerView selectedRowInComponent:0];
self.strPrintRepeat = [repeatPickerData objectAtIndex:row];
strPrintRepeat is nothing but a variable which store the string value of PickerView. That is :- NSString *strPrintRepeat.
Thanks Jay, I got it working with my picker that has one component. Can you help modify it though to work with my picker that has 2 components? I added the exact code I am using for 1 component picker in the question thanks.
I don't understand this answer...what exactly is repeatPickerData? How is that being populated?
@yourfriendzak repeatPickerData here I had just declared that but it will not came here. it will came on viewDidLoad method and it contains the value which we are going to display in UIPickerView. Thanks for asking question and if you still have doubts then you are most welcome to ask the question.
For a little clarification look at it this way. NSLog(@"%@", [self.arrayFields objectAtIndex:[self.queryPicker1 selectedRowInComponent:0]]); Where arrayFields is the data array for the UIPickerView. Where queryPicker1 is the UIPickerView. Where selectedRowInComponent:0 is the first column (if you have 2 columns in your picker and want the value for the 2nd use 1 instead of 0) of the UIPickerView.