在 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;
}