MonoTouch.Dialog简介

新建一个Single View Application项目

添加程序集 MonoTouch.Dialog.dll引用

删除 MainStoryboard.storyboard 

添加空类Task.cs

using System;

namespace APITest
{
	public class Task
	{
		public Task ()
		{
		}
		public string Name { get; set; }

		public string Description { get; set; }

		public DateTime DueDate { get; set; }
	}
}

  

在AppDelegate.cs中重写方法FinishedLaunching,改为如下代码

using System;
using System.Linq;
using System.Collections.Generic;

using Foundation;
using UIKit;
using MonoTouch.Dialog;

namespace APITest
{
	// 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=0;
		public override UIWindow Window {
			get;
			set;
		}
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			_window = new UIWindow (UIScreen.MainScreen.Bounds);
			_rootElement = new RootElement ("To Do List"){ new Section()};
			_addButton = new UIBarButtonItem (UIBarButtonSystemItem.Add);
			_addButton.Clicked+= (sender, e) => {
				++n;
				var task=new Task{ Name="task"+n , DueDate=DateTime.Now };
				var taskElement=new RootElement(task.Name){
					new Section(task.Name){new EntryElement(task.Name,"Enter Task Description",task.Description)},
					new Section(task.Name){new DateTimeElement("DueDate", task.DueDate)}
				};
				_rootElement[0].Add(taskElement);
			};
			_rootVC = new DialogViewController (_rootElement);
			_nav = new UINavigationController (_rootVC);
			_rootVC.NavigationItem.RightBarButtonItem = _addButton;
			_window.RootViewController = _nav;
			_window.MakeKeyAndVisible ();
			return true;
		}
		// This method is invoked when the application is about to move from active to inactive state.
		// OpenGL applications should use this method to pause.
		public override void OnResignActivation (UIApplication application)
		{
		}
		
		// This method should be used to release shared resources and it should store the application state.
		// If your application supports background exection this method is called instead of WillTerminate
		// when the user quits.
		public override void DidEnterBackground (UIApplication application)
		{
		}
		
		// This method is called as part of the transiton from background to active state.
		public override void WillEnterForeground (UIApplication application)
		{
		}
		
		// This method is called when the application is about to terminate. Save data, if needed.
		public override void WillTerminate (UIApplication application)
		{
		}
	}
}

  双击Info.plist

运行结果

 

posted @ 2015-05-07 20:53  成败在我手  阅读(207)  评论(0编辑  收藏  举报