0
我试图关注Xamarin的“Walkthrough - Creating an application using the Elements API”,当我触摸一个应该启动新屏幕以输入描述的“Task”时,代码崩溃和日期选择器。单击NavigationItem.RightBarButtonItem时会显示任务,但单击其中一个会导致应用程序在模拟器中关闭。Xamarin iOS“演练 - 使用Elements API创建应用程序”崩溃
代码没有太多东西,我也没有看到我出错的地方。
环境:
的Visual Studio 2012> Xamarin构建主机>的Mac OS 10.9.5
整个应用程序中的AppDelegate:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
using MonoTouch.Dialog;
namespace ElementsApiWalkthrough
{
public class Task
{
public Task(){}
public string Name { get; set; }
public string Description { get; set; }
public DateTime DueDate { get; set; }
}
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow _window;
RootElement _rootElement;
DialogViewController _rootVC;
UINavigationController _nav;
UIBarButtonItem _addButton;
int n;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
_window = new UIWindow(UIScreen.MainScreen.Bounds);
_rootElement = new RootElement("To Do List") { new Section() };
// code to create screens with MT.D will go here …
_rootVC = new DialogViewController(_rootElement);
_nav = new UINavigationController(_rootVC);
_window.RootViewController = _nav;
_window.MakeKeyAndVisible();
_addButton = new UIBarButtonItem(UIBarButtonSystemItem.Add);
_rootVC.NavigationItem.RightBarButtonItem = _addButton;
_addButton.Clicked += (sender, e) =>
{
++n;
var task = new Task { Name = "task " + n, DueDate = DateTime.Now };
var taskElement = new RootElement(task.Name){
new Section() {
new EntryElement (task.Name,
"Enter task description", task.Description)
},
new Section() {
new DateElement ("Due Date", task.DueDate)
}
};
_rootElement[0].Add(taskElement);
};
return true;
}
}
}