Dav*_*vid 40 cocoa-touch uipickerview ios
我想在UIPickerView组件中显示一组连续的数字,但它像Clock-> Timer应用程序的秒组件一样包围.我可以启用的唯一行为类似于Timer应用程序的hours组件,您只能在一个方向上滚动.
squ*_*art 46
将行数设置为大数量同样容易,并使其从较高值开始,用户很可能在很长一段时间内滚动滚轮 - 即便如此,情况会更糟糕碰巧是他们会触底.
- (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;
// ...
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*vid 21
我在这里找到了答案:
http://forums.macrumors.com/showthread.php?p=6120638&highlight=UIPickerView#post6120638
当它要求一行的标题时,给它:代码:
return [rows objectAtIndex:(row % [rows count])];
Run Code Online (Sandbox Code Playgroud)
当它说用户didSelectRow:inComponent:时,使用如下内容:
码:
//we want the selection to always be in the SECOND set (so that it looks like it has stuff before and after)
if (row < [rows count] || row >= (2 * [rows count]) ) {
row = row % [rows count];
row += [rows count];
[pickerView selectRow:row inComponent:component animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
UIPickerView似乎不支持原生包装,但你可以通过插入更多数据集来愚弄它,当选择器停止时,将组件居中到数据集的中间.
| 归档时间: |
|
| 查看次数: |
24103 次 |
| 最近记录: |