Tuesday, December 28, 2010

Circular Picker View

Hi to all iPhone Players, Some time while working on Picker View Controller may be you faced a issues of  limited picker view display, means your picker view wheel is not moving continuously, its stoping on the last Value. but you want it to move circularly with the same values.

here is a Solution to get the same effect :

just manipulate your picker view delegate methods like this...



- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSUInteger)row forComponent:(NSUInteger)component; {
NSMutableArray *strings = [NSMutableArray arrayWithCapacity:10];
[strings addObject:@"Zero"];
[strings addObject:@"One"];
[strings addObject:@"Two"];
[strings addObject:@"Three"];
[strings addObject:@"Four"];
[strings addObject:@"Five"];
[strings addObject:@"Six"];
[strings addObject:@"Seven"];
[strings addObject:@"Eight"];
[strings addObject:@"Nine"];
return [strings objectAtIndex:(row%10)];
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSUInteger)row inComponent:(NSUInteger)component {
[self pickerViewLoaded:nil];
}

- (NSUInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSUInteger)component {
return 16384;
}


-(void)pickerViewLoaded: (id)blah {
NSUInteger max = 16384;
NSUInteger base10 = (max/2)-(max/2)%10;
[myPickerView selectRow:[myPickerView selectedRowInComponent:0]%10+base10 inComponent:0 animated:false];
}


- (NSUInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}


to get the Source Code, click here.