我试图遵循Xamarin的“演练-使用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;
}
}
}
我使用了新的iPhone项目类型。使用“经典”模板中的iPhone项目修复了该项目。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句