1

iPhone アプリケーションの開発に MonoTouch を使用しています。モノタッチを使いたい。クライアントにデータを表示し、データを変更してからファイルに再度保存するためのダイアログ。

私のコードは、Xamarin チュートリアルのコードのようなものです: (元のサンプル リンク)

public enum Category
{
    Travel,
    Lodging,
    Books
}

public class ExpesObject{
    public string name;
}

public class Expense
{
    [Section("Expense Entry")]

    [Entry("Enter expense name")]
    public string Name;
    [Section("Expense Details")]

    [Caption("Description")]
    [Entry]
    public string Details;
    [Checkbox]
    public bool IsApproved = true;
    [Caption("Category")]
    public Category ExpenseCategory;
}

TableViewとても良いことを表しています。しかし問題は、この要素のデータをどのように保存して、他のクラスのアプリケーションで使用できるかということです。これを行うための最良の方法は何ですか? ユーザーが変更したときにデータをファイルに保存できると思います。しかし、ユーザーがいつデータを変更したかをどのように検出できるのでしょうか?

4

1 に答える 1

2

あなたが示した例では、Monotouch.Dialog の単純な Reflection API を使用しています。これは便利で簡単ですが、実際にできることが制限されます。Monotouch.Dialog のここ ( http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog/elements_api_walkthrough ) にある Elements API の使用方法を学習することをお勧めします。これにより、各項目をより詳細に制御できます。テーブル、および変更などを検出できるようにします。

表の各セル (たとえば、名前は編集可能なセルです) には、テキストの変更など、特定のことが発生したときのアクション/イベントがあります。

たとえば、上記の画面は、要素 API を使用して次のように作成できます。

public class ExpenseViewController : DialogViewController
{
    EntryElement nameEntry;

    public ExpenseViewController() : base(null, true)
    {
        Root = CreateRootElement();

        // Here is where you can handle text changing
        nameEntry.Changed += (sender, e) => {
            SaveEntryData(); // Make your own method of saving info.
        };
    }

    void CreateRootElement(){
         return new RootElement("Expense Form"){
             new Section("Expense Entry"){
                 (nameEntry = new EntryElement("Name", "Enter expense name", "", false))
             },
             new Section("Expense Details"){
                 new EntryElement("Description", "", "", false),
                 new BooleanElement("Approved", false, ""),
                 new RootElement("Category", new Group("Categories")){
                     new CheckboxElement("Travel", true, "Categories"),
                     new CheckboxElement("Personal", false, "Categories"),
                     new CheckboxElement("Other", false, "Categories")
                 }
             }
         };
    }

    void SaveEntryData(){
        // Implement some method for saving data. e.g. to file, or to a SQLite database.
    }

}

Elements API の使用を開始するには、次の領域を考慮してください。 ソース: https://github.com/migueldeicaza/MonoTouch.Dialog

MT.D イントロ: http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog

MT.D 要素のチュートリアル: http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog/elements_api_walkthrough

于 2013-03-18T18:00:51.170 に答える