如何在选择器视图中更改编号格式?

时间:2014-11-25 20:31:56

标签: ios objective-c xcode uipickerview

我是编码初学者,想只显示整数(1,2,3,4) 在我的UIPickerView而不是(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];
}

谢谢

2 个答案:

答案 0 :(得分:0)

您将要使用此方法:

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

Apple为这样的问题提供了很好的文档: 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

答案 1 :(得分:0)

您只需要将格式化的行返回给字符串。像这样:

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