从
Xamarin.com的例子可以建立基本的M.T.对话框应用程序,但如何构建现实生活中的应用程序?
你做:
1)从那里创建一个DialogViewController并树上每个视图/ RootElement,
2)为每个视图创建一个DialogViewController,并使用UINavigationController并根据需要推送它
根据你的答案,更好的反应是怎样的?我已经构建了示例任务应用程序,所以我了解向表中添加元素,单击它以转到“下一个”视图进行编辑,但是如何点击进行非编辑?如何点击一个按钮,如果答案是1,请去下一个视图?
修订:
可能没有一个正确的答案,但是我想出来的似乎对我们有用.来自上面的第2号是所选择的,下面是当前存在的代码示例.我们所做的是在AppDelegate中创建一个导航控制器,并在整个应用程序中访问它,如下所示:
public partial class AppDelegate : UIApplicationDelegate { public UIWindow window { get; private set; } //< There's a Window property/field which we chose not to bother with public static AppDelegate Current { get; private set; } public UINavigationController NavController { get; private set; } public override bool FinishedLaunching (UIApplication app,NSDictionary options) { Current = this; window = new UIWindow (UIScreen.MainScreen.Bounds); NavController = new UINavigationController(); // See About Controller below DialogViewController about = new AboutController(); NavController.PushViewController(about,true); window.RootViewController = NavController; window.MakeKeyAndVisible (); return true; } }
那么每个Dialog都有一个这样的结构:
public class AboutController : DialogViewController { public delegate void D(AboutController dvc); public event D ViewLoaded = delegate { }; static About about; public AboutController() : base(about = new About()) { Autorotate = true; about.SetDialogViewController(this); } public override void LoadView() { base.LoadView(); ViewLoaded(this); } } public class About : RootElement { static AboutModel about = AboutVM.About; public About() : base(about.Title) { string[] message = about.Text.Split(...); Add(new Section(){ new AboutMessage(message[0]),new About_Image(about),new AboutMessage(message[1]),}); } internal void SetDialogViewController(AboutController dvc) { var next = new UIBarButtonItem(UIBarButtonSystemItem.Play); dvc.NavigationItem.RightBarButtonItem = next; dvc.ViewLoaded += new AboutController.D(dvc_ViewLoaded); next.Clicked += new System.EventHandler(next_Clicked); } void next_Clicked(object sender,System.EventArgs e) { // Load next controller AppDelegate.Current.NavController.PushViewController(new IssuesController(),true); } void dvc_ViewLoaded(AboutController dvc) { // Swipe location: https://gist.github.com/2884348 dvc.View.Swipe(UISwipeGestureRecognizerDirection.Left).Event += delegate { next_Clicked(null,null); }; } }
根据需要创建一个子类的元素:
public class About_Image : Element,IElementSizing { static NSString skey = new NSString("About_Image"); AboutModel about; UIImage image; public About_Image(AboutModel about) : base(string.Empty) { this.about = about; FileInfo imageFile = App.LibraryFile(about.Image ?? "filler.png"); if (imageFile.Exists) { float size = 240; image = UIImage.FromFile(imageFile.FullName); var resizer = new ImageResizer(image); resizer.Resize(size,size); image = resizer.ModifiedImage; } } public override UITableViewCell GetCell(UITableView tv) { var cell = tv.DequeueReusableCell(skey); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default,skey) { SelectionStyle = UITableViewCellSelectionStyle.None,Accessory = UITableViewCellAccessory.None,}; } if (null != image) { cell.ImageView.ContentMode = UIViewContentMode.Center; cell.ImageView.Image = image; } return cell; } public float GetHeight(UITableView tableView,NSIndexPath indexPath) { float height = 100; if (null != image) height = image.Size.Height; return height; } public override void Selected(DialogViewController dvc,UITableView tableView,NSIndexPath indexPath) { //base.Selected(dvc,tableView,path); tableView.DeselectRow(indexPath,true); } }
@miquel
目前的工作流概念是一个应用程序,它以Default.png的jpg开始,该JPG可以逐渐进入第一个视图,并具有可以移动到主应用程序的流控制按钮.这个观点,我曾经在M.T.D. (MonoTouch.Dialog),它是具有图像的文本行的表.当每一行被单击时,它将移动到具有行/文本的另一个视图.
该应用程序还支持应用内购买,所以如果客户希望购买更多的产品,然后切换到另一个视图来处理购买.这部分是切换到M.T.D.的主要原因,正如我认为M.T.D.将是完美的.
最后,会有一个设置视图来重新启用购买等.
PS如何知道应用程序何时未被最小化?我们想再次显示褪色.