Sqlite 以monotouch在my UITableView上冗余显示的数据

Sqlite 以monotouch在my UITableView上冗余显示的数据,sqlite,uitableview,xamarin.ios,Sqlite,Uitableview,Xamarin.ios,我在使用SQLite作为数据库填充monotouch中的表时遇到问题。我的问题是它只选择最后插入的数据,并返回与所选表中数据数量相同的数据 例如,数据=iPhone,表中的数据数=30 它在表中返回iPhone 30次 代码如下: 主视图控制器 public override void ViewDidLoad () { base.ViewDidLoad (); LoadToolbarButtons (); LoadNavigationBarButto

我在使用SQLite作为数据库填充monotouch中的表时遇到问题。我的问题是它只选择最后插入的数据,并返回与所选表中数据数量相同的数据

例如,数据=iPhone,表中的数据数=30

它在表中返回iPhone 30次

代码如下:

主视图控制器

public override void ViewDidLoad ()
    {
      base.ViewDidLoad ();

      LoadToolbarButtons ();
      LoadNavigationBarButtons ();

      BL.Products MyProducts = new BL.Products();
      List<Products> productList = new List<Products>();

      POSDB.InitPOSDatabase ();
      POSDB.GetAllProducts (productList, MyProducts);

      tblProductList.Source = new ProductListDataSource(productList);
      tblProductList.Delegate = new ProductListDelegate();
    }
数据源

public class ProductListDataSource : UITableViewSource
{
public List<Products> ProductList = new List<Products>();
public BL.Products myProducts = new BL.Products();

public ProductListDataSource(List<Products> productList):base()
{
    this.ProductList = productList;
}

#region implemented abstract members of MonoTouch.UIKit.UITableViewSource
public override int RowsInSection (UITableView tableview, int section)
{
    if (ProductList.Count == 0) 
    {
        UIAlertView alert = new UIAlertView ("No Records!", "Please add some items to your table.", null, "OK", null);
        alert.Show ();
    }

    return ProductList.Count;
}

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
    string cellIdentifier = "Cell";
    UITableViewCell cellProduct = tableView.DequeueReusableCell(cellIdentifier);

    if (cellProduct == null)
    {
    cellProduct = new UITableViewCell(UITableViewCellStyle.Value1,cellIdentifier);
    }

    var products = this.ProductList[indexPath.Row];
    cellProduct.TextLabel.Text =string.Format("({0}) {1}", products.ProductID, products.ProductName);
    cellProduct.DetailTextLabel.Text = "$" + System.Convert.ToString(products.Price);

    return cellProduct;
}
#endregion
}

我的密码有问题吗?
提前谢谢你

如果在调试器中检查productList,它是否具有正确的数据?您的TableView逻辑看起来是正确的,因此我会检查您是否确实从SQLite返回了您期望的数据。我确信它是正确的,因为我一个接一个地插入了它,并且我还尝试获取它的主键,它返回了我插入的最后一项。您上一条语句中的意思是什么?你会检查我的工作吗?