index for UIPickerView like UITableView?

[亡魂溺海] 提交于 2020-01-16 12:18:07

问题


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?

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.


回答1:


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!

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.




回答2:


UIPickerViews are not designed to present a large list of items. Is there a reason why you can not just use a UITableView?




回答3:


Maybe the only way to do so is customize a UITableView, let it looks like a UIPickerView.



来源:https://stackoverflow.com/questions/7179748/index-for-uipickerview-like-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!