简体   繁体   中英

index for UIPickerView like UITableView?

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.

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

也许这样做的唯一方法是自定义UITableView,使其看起来像UIPickerView。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM