I want to use my uipicker to initialize a 5character string representation of a hex number. So in other words I need each component of the uipicker to show 0-9,A-F dose anyone have an idea on how this could be done or if it is even possible?
currently this is how my code looks.
//.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;
}
//...
Also how am I able to load the picker at the bottom of the screen. Thanks.
Updated code to represent this part
Updated pickerView:titleForRow:forComponent: method for hex representation this now dose what it is intended to do :).
Your delegate method
pickerView:titleForRow:forComponent:should be like,When you want to extract the string do this,
That should give you the hex string you need.
Addendum
To support infinite scroll, you will just need to return a sufficiently huge number for the number of rows like this,
and during initialization use the
selectRow:inComponent:animated:method to select a row somewhere in the middle so that user can scroll either ways.You will also need to change the methods mentioned above,
And the hex string extraction would be,