xcode - 如何创建 iOS 时区选择器?

标签 xcode ios4 ios5 xamarin.ios timezone

我的应用程序是飞行员的日志,我想让用户选择将应用程序放在他们选择的时区。航空公司飞行员可能会飞越世界各地,但在输入航类信息时必须引用他们的家乡时区。我想提供一个用户界面,允许他们选择一个时区选项,例如“本地”(设备本地,取决于他们的位置)、“UTC”,然后是“自定义”。

我正在使用 MonoTouch.Dialog,它允许您连接一个集合,但问题是在 iOS 中时区列表相当长。我使用 System.TimeZoneInfo 命名空间来检索时区列表,就像在 Windows 中一样。但是,iOS 使用诸如“美国/纽约、美国/XYZ 等”之类的表示形式。所以为了让这个列表易于管理,我需要通过在/上拆分来分解它,这样我就可以首先呈现一个国家列表,用户将点击它,然后一个辅助列表将呈现在 UITableView 中,即区域比如“纽约”。然后我将捕获时区并使用 System.TimeZoneInfo 方法从 UTC 转换为自定义时区。

我的问题是如何,特别是在 MonoTouch.Dialog 中,我可以有一个集合,然后是一个子集合。即国家的 UITableView 带有披露指标,可将您带到该国家/地区的地区?

在同一个注释中,是否还有其他人在 iOS(Xcode 或 MonoTouch)中实现了“时区”选择器/选择器?

感谢您的想法和帮助解决这个问题。

最佳答案

以下内容将为您提供您正在寻找的用户界面:

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);

它产生这个用户界面:

Main UI
(来源:tirania.org)

嵌套元素如下所示:

Nested
(来源:tirania.org)

关于xcode - 如何创建 iOS 时区选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8822291/

相关文章:

iphone - 在 UITableviewController 中调用 viewWillAppear

iphone - 我为使用 makefile 构建的 iO 寻找库项目

objective-c - 在 Controller 实例变量中存储现有对象时是否需要 'retain'?

xcode - 无法向引导服务器注册

ios - iOS 推送通知的可用声音列表

iphone - iOS 5 最佳实践(发布/保留?)

iphone - 我可以删除 App Store 上已有应用的分发配置文件吗?

iphone - 有没有办法在 iOS 应用程序中嵌入 Excel 图表?

ios - Google map 无法在 iOS 中加载,错误 -999

iphone - 我应该在 xcode 中从哪个模板开始?