Xamarin.ios 将Monotouch.Dialog元素值保存到文件
我正在使用MonoTouch开发我的iPhone应用程序。我想用Monotouch。对话框,用于向客户端显示某些数据,并允许客户端更改数据,然后再次将其保存到文件中 我的代码类似于Xamarin教程的代码:Xamarin.ios 将Monotouch.Dialog元素值保存到文件,xamarin.ios,monotouch.dialog,Xamarin.ios,Monotouch.dialog,我正在使用MonoTouch开发我的iPhone应用程序。我想用Monotouch。对话框,用于向客户端显示某些数据,并允许客户端更改数据,然后再次将其保存到文件中 我的代码类似于Xamarin教程的代码: 公共枚举类别 { 旅行, 住宿 书 } 公共类项目{ 公共字符串名称; } 公费 { [第节(“费用分录”)] [输入(“输入费用名称”)] 公共字符串名称; [第节(“费用明细”)] [标题(“说明”)] [条目] 公共字符串详细信息; [复选框] 公共bool IsApproved=真
公共枚举类别
{
旅行,
住宿
书
}
公共类项目{
公共字符串名称;
}
公费
{
[第节(“费用分录”)]
[输入(“输入费用名称”)]
公共字符串名称;
[第节(“费用明细”)]
[标题(“说明”)]
[条目]
公共字符串详细信息;
[复选框]
公共bool IsApproved=真;
[标题(“类别”)]
公共类支出类;
}
它代表了TableView
非常好。
但问题是,我们如何保存这些元素的数据并在其他应用程序中使用它们?这样做的最佳方式是什么?
我想当用户更改数据时,我们可以将数据保存到文件中。但我们如何检测用户何时更改数据 在您展示的示例中,您正在为Monotouch.Dialog使用简单反射API。虽然这很好也很简单,但它确实限制了你的能力。我建议您学习使用Monotouch.Dialog的Elements API(),它可以让您更好地控制表中的每一项,并能够检测更改,等等 每个表格单元格(例如,名称是一个单元格,您可以编辑)都有特定事件发生时的操作/事件,如文本被更改 例如,上面的屏幕可以通过elements 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,请考虑以下方面:
资料来源:
MT.D简介:
MT.D元素演练: