How to create iOS Time Zone Picker?

My application is a magazine for pilots, and I would like to give the user the opportunity to place the application in the time zone of their choice. Airline pilots can fly around the world, but when entering flight information, they need to contact their home time zone. I want to offer a user interface that allows them to select a time zone setting, such as Local (which is a local device, depending on their location), UTC, and then a hard user interface.

I use MonoTouch.Dialog, which allows you to connect a collection, but the problem is in iOS. The list of time zones is quite long. I use the System.TimeZoneInfo namespace to retrieve a list of time zones, as on Windows. However, iOS uses a presentation such as "United States / New York, USA / XYZ, etc.". Therefore, in order to keep this list manageable, I need to split it by dividing it by / so that I can present the list of countries, the user will touch this, and the secondary list will be presented in a UITableView, which is a region such as New York. Then I close the time zone and use the System.TimeZoneInfo methods to convert from UTC to a user time zone.

My question is how, in particular, in MonoTouch.Dialog, can I get a collection and then a sub-series. that is, a UITableView of countries with a disclosure indicator that will lead you to the regions for the country?

In the same note, did anyone else implement a timezone selector / selector in iOS (Xcode or MonoTouch)?

Thanks for your ideas and help with this problem.

+4
source share
2 answers

The following will give you the interface you are looking for:

var groups = from tz in TimeZoneInfo.GetSystemTimeZones () let name = tz.ToString () let idx = name.IndexOf ('/') where idx != -1 let first = name.Substring (0, idx) group tz by first into g select new { Region = g.Key, Zones=g }; var root = new RootElement ("TimeZones"){ new Section ("Regions"){ from r in groups select (Element) new RootElement (r.Region.ToString ()){ new Section () { from z in r.Zones select (Element) new StringElement (z.ToString ()) } } } }; dvc = new DialogViewController (root); 

This produces this interface:

Main ui
(source: tirania.org )

And the nested elements look like this:

Nested
(source: tirania.org )

+5
source

In the same note, did anyone else implement a timezone selector / selector in iOS (Xcode or MonoTouch)?

I have not seen anyone do just that. However, this article shows how to use UIPickerView to implement your own builders (next to what you want). It shouldn't be too hard to convert this to C #.

Once you have your own UITimeZonePicker , then it will be easy to create a TimeZoneElement for MonoTouch.Dialog (basically copy / paste DateElement ).

+1
source

Source: https://habr.com/ru/post/1390460/


All Articles