只是 UIPickerView 中的数字?

发布于 2024-10-06 19:11:26 字数 85 浏览 0 评论 0原文

有没有办法让 UIPickerView 将数字递增到无穷大? 哈哈。开玩笑,但说真的,我只想要一堆数字上升,但我不想全部硬编码。

提前致谢!

Is there a way to have a UIPickerView just have escalating numbers to infinity?
Haha. Just kidding, but seriously, I want just a bunch of numbers going up, but I don't want to have to hard-code it all.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放血 2024-10-13 19:11:28

我很确定这可以通过一些技巧来完成(一个自定义整数类,支持任意大的数字,并且一旦用户滚动所有 NSIntegerMax 行(即当用户滚动时)定期“滚动”到更高的数字集要行 NSIntegerMax,您以编程方式将它们滚动回第 0 行并显示“row + NSIntegerMax”,而不仅仅是“row”)。当它们重复滚动时,您将其更改为“row + NSIntegerMax * 2”等。

显然,您还必须这样做 但我怀疑这比你想要做的更花哨

,在这种情况下,你只想将这些代码行添加到你的视图控制器中:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return NSIntegerMax;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [NSString stringWithFormat:@"%d", row];
}

然后双击视图 nib 文件( *.xib 文件)以在 Interface Builder 中打开它,并将“数据源”出口连接到“文件所有者”(视图控制器),这将为您提供我能想象到的尽可能多的整数。

I'm pretty sure this can be done with some cleverness (a custom integer class that supports arbitrarily large numbers, and periodically "rolling over" to a higher set of numbers once the user has scrolled through all NSIntegerMax rows (i.e. when the user scrolls to row NSIntegerMax you programmatically scroll them back to row 0 and display "row + NSIntegerMax" instead of just "row"). As they scroll through repeatedly you change it to "row + NSIntegerMax * 2", etc.

Obviously you also have to handle them changing directions are some point.

But I suspect that's what fancier than what you're looking to do. In this case you just want to add these lines of code to your View Controller:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return NSIntegerMax;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [NSString stringWithFormat:@"%d", row];
}

Then double click on the View nib file (the *.xib file) to open it in Interface Builder, and connect the "data source" outlet to the "File Owner" (the View Controller). That will get you as many integers as I could ever imagine someone scrolling to.

离不开的别离 2024-10-13 19:11:28

看看​​这个问题。这是你的问题的一个变体。

Have a look at this question. It is a variation on your problem.

許願樹丅啲祈禱 2024-10-13 19:11:28

你可以只使用 UIStepper。我知道你问过 UIPicker 但你真的需要使用那个类还是你用它来解释你想要什么样的东西

You could just use a UIStepper. I know you asked about UIPicker but do you really need to use that class or were you using it to explain what kind of thing you wanted

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文