0

SQLite をデータベースとして使用して monotouch でテーブルを作成する際に問題があります。私の問題は、挿入された最後のデータのみを選択し、選択したテーブル内のデータの数だけ返すことです。

元。data=iPhone、テーブル内のデータ数 = 30。

テーブル内の iPhone を 30 回返します。

コードは次のとおりです。

MainViewController

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

}

コードに何か問題がありますか? 前もって感謝します!

4

0 に答える 0