如何使UIPickerView组件环绕? [英] How do you make an UIPickerView component wrap around?
问题描述
我想在UIPickerView组件中显示一组连续的数字,但是它像Clock-> Timer应用程序的秒组件一样。我可以启用的唯一行为看起来像Timer应用程序的小时组件,您只能在一个方向滚动。
I would like to show a set of consecutive numbers in a UIPickerView component but have it wrap around like the seconds component of the Clock->Timer application. The only behavior I can enable looks like the hours component of the Timer application, where you can scroll in only one direction.
推荐答案
它很容易将行数设置为一个大数字,并使其开始在一个高的价值,几乎没有机会,用户将滚动滚轮很长一段时间 - 即使这样,更糟的是,
It's just as easy to set the number of rows to a large number, and make it start at a high value, there's little chance that the user will ever scroll the wheel for a very long time -- And even then, the worse that will happen is that they'll hit the bottom.
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
// Near-infinite number of rows.
return NSIntegerMax;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
// Row n is same as row (n modulo numberItems).
return [NSString stringWithFormat:@"%d", row % numberItems];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.pickerView = [[[UIPickerView alloc] initWithFrame:CGRectZero] autorelease];
// ...set pickerView properties... Look at Apple's UICatalog sample code for a good example.
// Set current row to a large value (adjusted to current value if needed).
[pickerView selectRow:currentValue+100000 inComponent:0 animated:NO];
[self.view addSubview:pickerView];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSInteger actualRow = row % numberItems;
// ...
}
这篇关于如何使UIPickerView组件环绕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!