在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;
}
}
}
谢谢Poupou!在应用你的建议后,这是修复它的代码。
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;
}
答案 0 :(得分:3)
在MonoTouch.Dialog中使用这样的选择器时,拾取器不是模态的。因此,导航用户界面将让您返回上一个视图。 OTOH将通过这样做隐藏起来:
var navigationController = new UINavigationController();
window.AddSubview (navigationController.View);
注意:这也是一个(different)问题,因为它不会保留对navigationController
的引用。
你应该尝试用以下内容替换上面的内容(并在创建DialogViewController
后移动它):
window.RootViewController = dialogViewController;
这应该让默认导航UI返回并允许您从日期选择器返回。