10

Xamarin.comの例から基本的なM.T. Dialogアプリを構築できますが、実際のアプリケーションを構築するにはどうすればよいでしょうか?

あなたは:

1) そこから 1 つDialogViewControllerのツリーを作成するview/RootElementか、または、

2) DialogViewControllerfor every ビューを作成し、必要に応じて使用し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);
    }
}

@ミケル

ワークフローの現在のアイデアは、Default.png の jpg で始まり、最初のビューにフェードインし、フロー コントロール ボタンがメイン アプリに移動するアプリです。の前に作業していたこのビューはM.T.D. (MonoTouch.Dialog)、画像を含むテキスト行のテーブルです。各行をクリックすると、行/テキストをより詳細に表示する別のビューに移動します。

アプリはアプリ内購入もサポートしているため、クライアントが製品をさらに購入したい場合は、別のビューに切り替えて購入を処理します。に乗り換えた一番の理由はこの部分で、ぴったりM.T.D.だと思ったからです。M.T.D.

最後に、購入などを再度有効にするための設定ビューがあります。

PS アプリが最小化されていないことをどのように知ることができますか? フェードイン画像をもう一度お見せしたいと思います。

4

3 に答える 3

1

あなたが述べたオプション2も使用します。ルートビューごとにツールバーオプションを編集できるため、非常にうまく機能します。

于 2012-09-27T15:34:20.637 に答える
1

私は自分自身に同じ質問をしてきました。Funq Dependency Injection フレームワークを使用し、ビューごとに新しい DialogViewController を作成しました。これは事実上、私が ASP.NET MVC アプリケーションの開発で以前に使用したのと同じアプローチであり、コントローラー ロジックを適切に分離しておくことができることを意味します。ビューごとに DialogViewController をサブクラス化して、特定のコントローラーに必要なアプリケーション データをコントローラーに渡すことができるようにします。これが推奨されるアプローチかどうかはわかりませんが、今のところうまくいっています。

私も TweetStation アプリケーションを調べましたが、参考になると思いますが、関連するドキュメントには、MonoTouch アプリケーションを構築する方法の例になろうとしているわけではないと具体的に書かれています。

于 2012-05-28T09:17:47.003 に答える
0

オプション 2 は、それぞれをより詳細に制御できるため、より実現可能ですDialogViewController。ビューを条件付きでロードする場合にも役立ちます。

于 2014-06-02T10:27:42.457 に答える