Xamarin.ios 在MonoTouch.Dialog中,我需要做什么才能使日期时间选择器具有;“好的”;及;取消“;选项
在MonoTouch.Dialog中,我需要做什么才能使日期时间选择器具有“确定”和“取消”选项 在此示例代码中,当您单击DateTime元素并导航到选取器屏幕时,在导航到日期选取器后,无法选择或取消Xamarin.ios 在MonoTouch.Dialog中,我需要做什么才能使日期时间选择器具有;“好的”;及;取消“;选项,xamarin.ios,monotouch.dialog,Xamarin.ios,Monotouch.dialog,在MonoTouch.Dialog中,我需要做什么才能使日期时间选择器具有“确定”和“取消”选项 在此示例代码中,当您单击DateTime元素并导航到选取器屏幕时,在导航到日期选取器后,无法选择或取消 [Register ("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { protected UIWindow window; protected UINavigationContro
[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;
}
在MonoTouch.Dialog中这样使用时,选择器不是模态的。因此,是导航UI让您返回到上一个视图。这样做将隐藏的OTOH:
var navigationController = new UINavigationController();
window.AddSubview (navigationController.View);
注意:这也是一个()问题,因为它不会保留对navigationController
的引用
您应该尝试用以下内容替换上述内容(并在创建对话框ViewController
后将其移动):
这将返回默认的导航UI,并允许您从日期选择器返回。谢谢!我在上面添加了修复。
[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;
}
}
}