3

在 MonoTouch.Dialog 中,我需要做什么才能使日期时间选择器具有“确定”和“取消”选项?

在此示例代码中,当您单击 DateTime 元素导航到选择器屏幕时,在导航到日期选择器后无法选择或取消。

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
    protected UIWindow window;
    protected UINavigationController navigationController;
    protected RootElement rootElement;
    protected DialogViewController dialogViewController;        

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);
        var navigationController = new UINavigationController();
        window.AddSubview (navigationController.View);
        window.MakeKeyAndVisible ();

        rootElement = CreateJsonItems();
        dialogViewController = new DialogViewController (rootElement, true);
        navigationController.PushViewController (dialogViewController, true);

        return true;
    }

    protected RootElement CreateJsonItems()
    {
        var json = 
            @"{
                ""title"": ""Json Sample"",
                ""sections"": [{
                    ""header"": ""Dates and Times"",
                    ""elements"": [{
                        ""type"": ""datetime"",
                        ""caption"": ""Date and Time"",
                        ""value"": ""Sat, 01 Nov 2008 19:35:00 GMT""
                    }, {
                        ""type"": ""date"",
                        ""caption"": ""Date"",
                        ""value"": ""10/10""
                    }, {
                        ""type"": ""time"",
                        ""caption"": ""Time"",
                        ""value"": ""11:23""
                    }]
                }]
            }";

        using(var reader = new StringReader(json))
        {
            var jsonObject = JsonObject.Load(reader) as JsonObject;
            var jsonElement = JsonElement.FromJson(jsonObject);
            return jsonElement;
        }
    }
}

谢谢普普!_ 在应用您的建议后,这是修复它的代码。

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);
    rootElement = CreateJsonItems();
    var dialogViewController = new DialogViewController(rootElement);
    navigationController = new UINavigationController(dialogViewController);
    window.Add (navigationController.View);
    window.MakeKeyAndVisible ();
    return true;
}
4

1 回答 1

3

在 MonoTouch.Dialog 中这样使用时,选择器不是模态的。因此,导航 UI可以让您返回上一个视图。OTOH 将通过这样做隐藏:

   var navigationController = new UINavigationController();
   window.AddSubview (navigationController.View);

注意:这也是一个(不同的)问题,因为它不会保留对navigationController.

您应该尝试用以下内容替换上述内容(并在创建后移动它DialogViewController):

   window.RootViewController = dialogViewController;

这应该让默认导航 UI 返回并允许您从日期选择器返回。

于 2012-02-18T15:55:04.063 回答