gpt4 book ai didi

iphone - UIPickerView无限行

转载 作者:行者123 更新时间:2023-12-03 18:50:36 26 4
gpt4 key购买 nike

如 UIDatePicker 中所示,您可以无限地向上滚动(也可以向下滚动)。我也想实现这一目标,因为我希望人们选择一个日期,例如:

2010 年 1 月 1 日2010 年 1 月 2 日...2010年12月30日2010年12月31日2011 年 1 月 1 日..

所以它可以永远持续下去。我将如何实现这个目标?因为我只能在委托(delegate)中给出特定数量的行。

最佳答案

我认为您实际上无法创建 UIPickerView 循环,但我过去所做的方法是从 numberOfRowsInComponent 返回一个非常大的数字,然后计算row 从 viewForRow 返回适当的 View ,如下所示:

// picker data source:
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger) component
{
// to make it look like the picker is looping indefinetly,
// we give it a really large length, and then in the picker delegate we consider
// the row % (actual length) instead of just the row.
return INT16_MAX;
}


// picker delegate:
-(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger) row forComponent:(NSInteger) component reusingView:(UIView *)view
{
// to make it look like the picker is looping indefinetly,
// we give it a really large length in the picker data source, and then we consider
// the row % actual_length instead of just the row.
row = row % actual_length;
// where actual length is the number of options that will be looping

// ... do whatever
}

并在初始化中:

- (void)viewDidLoad {
[super viewDidLoad];

// ... whatever other initialization...

// to make it look like the picker is looping indefinetly ,
// we give it a really large length in the picker data source, and then we consider
// the row % actual_length instead of just the row,
// and we start with the selection right in the middle, rounded to the
// first multiple of actual_length so we start the selection on
// the first option in the list.
[myPicker selectRow:(INT16_MAX/(2*actual_length))*actual_length inComponent:0 animated:NO];
}

关于iphone - UIPickerView无限行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3618816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com