In MonoTouch.Dialog what do I need to do to make datetime pickers have and "ok" and "cancel" option?
In this example code when you click a DateTime element you navigate to the picker screen there is no way to select or cancel after you navigate to the date picker.
[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;
}
}
}
Thank you Poupou! after applying your advice this is the code that fixed it.
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;
}