UIPickerView的索引,例如UITableView? [英] index for UIPickerView like UITableView?

查看:39
本文介绍了UIPickerView的索引,例如UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像为UITableView的右侧具有UITableView的索引那样为UIPickerView编制索引?

Is it possible to have an index for a UIPickerView like one can have an index for a UITableView on the right hand side of the UITableView?

我问的原因是,如果一个人在UIPickerView中有大量项目列表,那么滚动到列表末尾可能要花费相当长的时间.

The reason I am asking is that if one has a large list of items in the UIPickerView, it can take quite a while to scroll to the end of the list.

推荐答案

您可能要考虑使用UITableView,但这不能回答您的原始问题.凭空想象,一切皆有可能,仅因为您无法在Cocoa中毫不费力地做某事并不意味着您根本不应该尝试!

You might want to consider using a UITableView, but that doesn't answer your original question. Anything is possible with a little imagination, and just because you can't do something effortlessly in Cocoa doesn't mean you shouldn't try at all!

我整理了一个小型演示项目,展示了一种实现方法.基本上,它涉及一个UIView子类,该子类将自身附加到UIPickerView.它允许您将索引标题(NSStrings)与UIPickerView中的行相关联,并且当您触摸标题时,它会滚动到相应的行.

I put together a small demo project that shows one way of doing it. Basically, it involves a UIView subclass that attaches itself to a UIPickerView. It allows you to associate index titles (NSStrings) with rows in the UIPickerView, and when you touch the titles, it scrolls to the appropriate row.

您可以通过添加对具有多个组件的选取器视图的支持,改善触摸处理,添加自定义标签支持等来改善它.

You could improve it by adding support for picker views with more than one component, improving the touch handling, adding custom label support, etc.

这篇关于UIPickerView的索引,例如UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆