构建MonoTouch.Dialog应用程序

Chu*_*age 10 uinavigationcontroller xamarin.ios monotouch.dialog dialogviewcontroller

Xamarin.com上的示例中,您可以构建基本M.T. Dialog应用程序,但是如何构建真实应用程序?

你呢:

1)从那里创建一个单独的DialogViewControllerview/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;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后每个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); };            
    }
}
Run Code Online (Sandbox Code Playgroud)

根据需要创建元素的子类:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

@miquel

当前工作流的想法是一个应用程序,它以一个jpg的Default.png开始,逐渐淡入第一个视图,并带有一个可以移动到主应用程序的流控制按钮.这个视图,我之前工作过M.T.D. (MonoTouch.Dialog),它是一个带有图像的文本行表.单击每一行时,它将移动到另一个具有更详细的行/文本的视图.

该应用程序还支持应用内购买,因此如果客户希望购买更多产品,则切换到另一个视图以进行购买.这部分是切换到的主要原因M.T.D.,因为我认为M.T.D.这将是完美的.

最后会有一个设置视图来重新启用购买等.

PS如何知道应用程序何时未最小化?我们想再次展示淡入淡出的形象.

Dav*_*rke 1

我一直在问自己同样的问题。我使用了Funq依赖注入框架,并为每个视图创建了一个新的 DialogViewController。这实际上与我之前开发 ASP.NET MVC 应用程序时使用的方法相同,并且意味着我可以很好地分离控制器逻辑。我为每个视图创建了 DialogViewController 子类,这允许我将特定控制器所需的任何应用程序数据传递到控制器。我不确定这是否是推荐的方法,但到目前为止它对我有用。

我也查看了 TweetStation 应用程序,发现它是一个有用的参考,但相关文档特别指出它并不是试图成为如何构建 MonoTouch 应用程序的示例。