Reputation: 661
I am using a UIPickerView and currently their is only a single object in it. How can I display that single object on label. It has this weird property that when we use pickerView the data is not set selected by default.Once we choose another object or roll it, then only any particular object is selected. Hence if only one object is their in pickerView. It does not count as selected even though when you tap on that single object. I tried a lot but found that if their are more than one object then only you can display the selected object on label but not if their is only one object.
Upvotes: 0
Views: 202
Reputation: 6662
You need to make a code that is triggered when the UIPickerView changes, like this:
#pragma
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
//Action that triggers following code:
{
NSString *nameString = [nameOnMutubaleArrayYouWannaGetDataFrom objectAtIndex:[picker selectedRowInComponent:0]]; //Or 1 if u have multiple rows
NSString *labelString = [[NSString alloc]initWithFormat:
@" %@ ", nameString];
labelOutput.text = labelString;
Hope this helps.
Upvotes: 2