我正在尝试获取客户数据以将它们解析为客户对象以在TableView上显示。以下代码有时可用,有时不适用。每当它崩溃时,即使我每次运行相同的代码,它都会显示客户数据在foreach循环中为空。我不知道在这种情况下可能会出现什么问题。我在这个平台上很新。如果我缺少任何/额外的信息,请告诉我。以Xamarin形式崩溃数据提取
namespace TableViewExample
{
public partial class MyDataServices : ContentPage
{
private ODataClient mODataClient;
private IEnumerable <IDictionary<string,object>> Customers;
public MyDataServices()
{
InitializeComponent();
InitializeDataService();
GetDataFromOdataService();
TableView tableView = new TableView{ };
var section = new TableSection ("Customer");
foreach (var customers in Customers) {
//System.Diagnostics.Debug.WriteLine ((string)customers ["ContactName"]);
var name = (string)customers ["ContactName"];
var cell = new TextCell{ Text = name };
section.Add (cell);
}
tableView.Root.Add (section);
Padding = new Thickness (10, 20, 10, 10);
Content = new StackLayout() {
Children = { tableView }
};
}
private void InitializeDataService(){
try {
mODataClient = new ODataClient ("myURL is here");
}
catch {
System.Diagnostics.Debug.WriteLine("ERROR!");
}
}
private void GetDataFromOdataService(){
try {
Customers = mODataClient.For ("Customers").FindEntries();
}
catch {
System.Diagnostics.Debug.WriteLine("ERROR!");
}
}
}
}
它在哪里崩溃?你得到的例外是什么?你在运行什么?你是否会崩溃模拟器?或者在设备上?哪个模拟器?哪个设备? – 2014-10-09 14:20:34
它在模拟器上崩溃,我还没有在设备上测试过。我只在模拟器中用iOS 8.0测试iPhone 5 – casillas 2014-10-09 14:24:32
这表明客户是空的。我试图得到那个错误,但是运气不好,即使我已经运行了这个应用程序将近30次,它仍然没有出现。 – casillas 2014-10-09 14:30:23