我试图关注Xamarin" Walkthrough - Creating an application using the Elements API"当我触摸"任务时,我的代码崩溃了。应该启动一个新的屏幕来输入描述和日期选择器。单击NavigationItem.RightBarButtonItem时会显示任务,但单击其中一个会导致应用程序在模拟器中关闭。
代码并不多,我也不知道我哪里出错了。
环境:
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;
}
}
}
答案 0 :(得分:0)
我使用过新的iPhone项目类型。使用“经典”模板中的iPhone项目修复它。