Ollie
Ollie

Reputation: 207

UIPickerView set selected

I have a uipickerview that you can select items that have been set into an array but I am struggling to work out how to set the text of a uilabel to the selected option.

Here is the code that I am using to create the uipicker delegate and datasource:

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [treatments count];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
      return[[treatments objectAtIndex:row]valueForKey:@"treatmentName"];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

}

All I know is that it has to be done in the uipicker didselectrow function

Thanks in advance

Upvotes: 1

Views: 635

Answers (1)

Pratik
Pratik

Reputation: 2399

set text label in below method

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
      yourLbl.text = [[treatments objectAtIndex:row]valueForKey:@"treatmentName"];
}

Upvotes: 2

Related Questions