Search code examples
iosobjective-cxcodeuipickerview

How can I change numbering format in picker view?


I am beginner in coding and would like to display only integers (1 , 2 , 3 , 4) in my UIPickerView rather than (0.0 , 0.1 , 0.3 , 0,4).

-(NSString *)pickerView:(UIPickerView *)pickerView
            titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [NSString stringWithFormat:@"%ld, %ld",(long)component,(long)row];
}

thanks


Solution

  • You are going to want to use this method:

        - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    

    Apple provides great documentation for issues like this: https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIPickerView_Class/index.html https://developer.apple.com/library/IOS/documentation/UIKit/Reference/UIPickerViewDelegate_Protocol/index.html.