2016-10-24 12 views
0

私は現在、Visual Studioにxamarinでiphoneアプリケーションを開発中です。私は初心者です。Xamarin.ios CollectionViewアイテムの削除と挿入

私はCollectionViewを使用しています。これは、リストを持っており、CollectionViewSource.csのIDの異なる8つの項目が含まれます。今、私はアイテムが押された場合、すべてのアイテムを削除し、それを補充、希望

ProductCategoryList.Add (new ProductCategorys() {Categoryid = 1, ProductCategoryName = "testname", ProductCategoryImage = UIImage.FromFile ("productcat/maincat/testpic.jpg")}); 

を。私が持っているProductCategoryCollectionDelegate.csで :

削除については
Public override Boolean ShouldSelectItem (UICollectionView collectionView, NSIndexPath indexPath) 

と私はこれらの2つの方法

Public void DeleteItems (NSIndexPath [] indexPaths) 
Public void InsertItems (NSIndexPath [] indexPaths) 

を発見した挿入(xamarinドキュメントが非常に不足している)

どのように使用することができますリストを完全に空にして新しいアイテムを追加するための2つのメトード?私が代わりにCollectionViewTableViewを撮影したヘルプ

+0

HI Andreas、問題を解決しましたか?私は同じ問題で立ち往生しています。 – TheDeveloper

答えて

0

ため

感謝。この機能を 直接Tablesourceクラス内の項目を削除することが可能である:

public override void CommitEditingStyle(UITableView tableView, 
          UITableViewCellEditingStyle editingStyle, 
          Foundation.NSIndexPath indexPath) 
{ 
     switch (editingStyle) 
     { 
      case UITableViewCellEditingStyle.Delete: 
       AppDelegate.DAUtil.setBasketItemStatusByBasketID(
        basketitems[indexPath.Row].ZBASKETID, "2"); 
       // remove the item from the underlying data source 
       basketitems.RemoveAt(indexPath.Row); 
       // delete the row from the table 
       tableView.DeleteRows(new NSIndexPath[] { indexPath }, 
        UITableViewRowAnimation.Fade); 
       break; 
      case UITableViewCellEditingStyle.None: 
       Console.WriteLine("CommitEditingStyle:None called"); 
       break; 
     } 
} 

public override bool CanEditRow(UITableView tableView, 
          NSIndexPath indexPath) 
{ 
     return true; 
    // return false if you wish to disable editing 
    // for a specific indexPath or for all rows 
} 

表のソースが一覧です。または、TableSourceを次のように再読み込みできます。

tablename.ReloadData(); 
関連する問題