My app is a logbook for pilots and I'd like to give the user the option of putting the app in the time zone of their choice. Airline pilots may fly across the world but have to reference their home base time zone when entering flight information. I want to offer a UI that allows them to select a time zone option such as "Local" (which is device local, depending on their location), "UTC", and then the hard one "custom".
I'm using MonoTouch.Dialog which allows you to wire up a collection but the problem is in iOS the list of time zones is rather long. I use the System.TimeZoneInfo namespace to retrieve the list of time zones just like in Windows. However, iOS uses a presentation such as "United States/New York, United States/XYZ, etc.". So to keep this list manageable I'm going to need to break this up by splitting on the / so I can first present a list of countries, the user will tap that and a secondary list will then present in a UITableView which is the regions such as "New York." I'll then capture the time zone and use the System.TimeZoneInfo methods to convert from UTC to the custom time zone.
My question is how, particularly in MonoTouch.Dialog, can I have a collection and then a sub-collection. i.e. a UITableView of Countries with a disclosure indicator that takes you to the regions for the country?
On this same note, has anyone else implemented a "time zone" selector/picker in iOS (Xcode or MonoTouch)?
Thank you for your ideas and help with this problem.
The following will get you the UI 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);
It produces this UI:
(source: tirania.org)
And the nested elements look like this:
(source: tirania.org)