How do I rewrite the UIDatePicker component?

后端 未结 2 1277
不知归路
不知归路 2020-12-14 03:19

I\'ve noticed that the UIDatePicker doesn\'t work with NSHebrewCalendar in iOS 5.0 or 5.1. I\'ve decided to try and write my own. I\'m confused as to how to populate the dat

2条回答
  •  时光取名叫无心
    2020-12-14 04:02

    I assume you're using a UIPickerView?

    UIPickerView works like a UITableView in that you specify another class to be the dataSource/delegate, and it gets it's data by calling methods on that class (which should conform to the UIPickerViewDelegate/DataSource protocol).

    So what you should do is create a new class that is a subclass of UIPickerView, then in the initWithFrame method, set it to be its own datasource/delegate and then implement the methods.

    If you've not used a UITableView before, you should familiarise yourself with the datasource/delegate pattern because it's a bit tricky to get your head around, but once you understand it it's very easy to use.

    If it helps, I've written a custom UIPicker for selecting countries. This works in pretty much the same way you'll want to do your class, except that I'm using an array of country names instead of dates:

    https://github.com/nicklockwood/CountryPicker

    With regard to the memory question, the UIPickerView only loads the labels that are visible onscreen and recycles them as they scroll off the bottom and back onto the top, calling your delegate again each time it needs to display a new row. This is very memory efficient as there will only be a few labels on screen at a time.

提交回复
热议问题