0

私は2〜3のセクションを持つUITableViewを持っています。私は、各セクションの1行を選択できる機能を実装したいと考えています。すべてのUITableViewSection iOS用の単一の選択Xamarin

そうような何か: - 私はのUITableView上で複数選択を可能にしようとしている

enter image description here

。しかし、それは私がすべてのセクションから複数の行を選択することができます。私はすべてのセクションから一度に1つの行だけを選択したい。

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
     { 
      var cell = tableView.CellAt(indexPath); 


       if (cell.Accessory == UITableViewCellAccessory.None) 
       { 
        cell.Accessory = UITableViewCellAccessory.Checkmark; 
       } 
       else 
       { 
        cell.Accessory = UITableViewCellAccessory.None; 
       } 


      selectedSection = indexPath.Section; 

     } 
     public override void RowDeselected(UITableView tableView, NSIndexPath indexPath) 
     { 
      var cell = tableView.CellAt(indexPath); 
      cell.Accessory = UITableViewCellAccessory.None; 
     } 

答えて

0

リストを使用して、前回選択したすべてのセクションのフラグを保存できます。

List<NSIndexPath> selectList = new List<NSIndexPath>(); 
for(int i = 0; i < tableviewDatasource.Count; i++) 
{ 
     //initial index 0 for every section 
     selectList.Add(NSIndexPath.FromRowSection(0, i)); 
} 

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
{ 
    //anti-highlight last cell 
    NSIndexPath lastindex = selectList[indexPath.Section]; 
    var lastcell = tableView.CellAt(lastindex); 
    lastcell.Accessory = UITableViewCellAccessory.None; 

    //highlight selected cell 
    var cell = tableView.CellAt(indexPath); 
    cell.Accessory = UITableViewCellAccessory.Checkmark; 

    //update the selected index 
    selectList.RemoveAt(indexPath.Section); 
    selectList.Insert(indexPath.Section, indexPath); 
} 

enter image description here

関連する問題