我想用我的 uipicker 来初始化一个 5 字符的十六进制数字的字符串表示。所以换句话说,我需要uipicker的每个组件显示0-9,AF剂量任何人都知道如何做到这一点,或者甚至可能吗?
目前这就是我的代码的外观。//。H
//...
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, UIPickerViewDelegate, UIPickerViewDataSource> {
IBOutlet UIPickerView *hexPicker;
//...
//.m
//.....
- (void)viewDidLoad {
//hexPicker = [[UIPickerView alloc] init];
//initalise icker at bottom of screen
hexPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 244, 320, 216)];
hexPicker.delegate = self;
hexPicker.dataSource = self;
hexPicker.showsSelectionIndicator = YES;
[self.view addSubview:hexPicker];
[super viewDidLoad];
}
//.....
#pragma mark UIPickerViewDelegate methods
- (NSString*)pickerView:(UIPickerView*)pv titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//This only shows as digits/integers
//return [NSString stringWithFormat:@"%d",row];
//this shows those digits as hex
[[NSString stringWithFormat:@"%x",row] uppercaseString];
}
#pragma mark UIPickerViewDataSource methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pv
{
return 5;
}
- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
return 16;
}
//...
另外我如何能够在屏幕底部加载选择器。谢谢。 更新了代码来表示这部分 更新了 pickerView:titleForRow:forComponent: 十六进制表示的方法,这现在完成了它打算做的事情:)。