在示例中,您使用Monotouch.Dialog的簡單Reflection API。雖然這很好很容易,但它確實限制了你可以做的事情。我建議學習使用Monotouch.Dialog的這裏看到的(http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog/elements_api_walkthrough)元素API,它將給你對錶中每個項目的更多控制,並且能夠檢測到變化等。
每個表格單元格(例如Name是一個可以編輯的單元格)具有某些事情發生時的動作/事件,例如正在更改文本。
例如,上面的屏幕可以使用元素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.
}
}
考慮這些地區開始使用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