我正在开发一个应用程序,我对 UIPickerView 中的行循环感到震惊。谁能帮帮我吗?如果有人会发布解决方案,那将有很大帮助。我希望 UIPickerView 中的行以循环方式连续滚动而没有终点。
2662 次
3 回答
1
我不认为这是可能的。我听说有人多次重复值列表,并在中间的某个地方开始用户。
于 2009-11-24T01:18:49.093 回答
1
有可能的。对于任何需要它的人,试试这个。
于 2011-05-26T06:49:32.697 回答
0
它确实有效,只是观察记忆。告诉未显示的项目未存储,因此可以使列表很大。如果担心,请与探查器联系。将行数设置为大数字同样容易,并使其以较高的值开始,用户滚动滚轮很长时间的可能性很小——即使那样,情况越糟发生的是他们会触底。
(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
// Near-infinite number of rows. use NSIntegerMax, if memory problem, use less say 2000
return 2000;
}
(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]; // or your strings (this is for double. numberItems is your list size.
}
(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:3+1000 inComponent:0 animated:NO]; //pick about half the max you made earlier or about 100000 if using NSIntegerMax
[self.view addSubview:pickerView];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSInteger actualRow = row % numberItems; //nb numberItems is your list size
// ...
}
乔恩
于 2013-03-03T01:59:40.753 回答