Search code examples
iosiphoneobjective-cuipickerviewdidselectrowatindexpath

How to read UIPicker selected text


I have created a UIPicker, which has about eight or nine possible strings. Depending on what view loads the UIPicker will depend on which strings are shown.

Due to this in my pickerView:didSelectRow:inComponent so I was wondering if there is a way when the user selects a row if I can get the textvalue that is in that.

This way in the didselectrow method I can perform different actions depending on the string value that was selected.

Current this is what I have:

#pragma mark - Picker Delegates
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

// get rowString somehow?
    // ReloadView
    if ([rowString isEqualToString:@"one Of the Values"]) {

     }
    // more if statements here.
}

Solution

  • Just read the value from the data source for that row then compare:

    NSString *rowString = (NSString *)[self.pickerArray objectAtIndex:row];
    if ([rowString isEqualToString:@"one Of the Values"]) {
    
     }