2017-07-25 51 views
0

我有一個UITableViewController和每個部分中的複選框列表。什麼是正確的方式來如何刪除UITableViewController中「其他行」的複選標記

  • 取行的部分
  • 更改部分的複選框,這樣我正確地更新我的支持數據視圖,以及UX看法呢?

...換句話說,我想部分1.我用NSIndexPath試圖內只有一個勾選然而屬性爲只讀。

enter image description here

代碼

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
    { 
     if (indexPath.Section ==1) 
     { 
      var thisCell = tableView.CellAt(indexPath); 

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

     if (indexPath.Section ==2) 
     { 
      var thisCell = tableView.CellAt(indexPath); 

      if (thisCell.Accessory == UITableViewCellAccessory.None) 
      { 
       thisCell.Accessory = UITableViewCellAccessory.Checkmark; 

       // Somehow deselect all the checkboxes in the other rows 
       // I can't set NSIndexPath properties on a new object... so I'm stuck 

      } 
      else 
      { 
       thisCell.Accessory = UITableViewCellAccessory.None; 
      } 
     } 
    } 

回答

0

創建NSIndexPath的方式是坐落在一個靜態方法...

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
    { 
     if (indexPath.Section ==1) 
     { 
      var thisCell = tableView.CellAt(indexPath); 

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

     if (indexPath.Section ==2) 
     { 
      var thisCell = tableView.CellAt(indexPath); 

      if (thisCell.Accessory == UITableViewCellAccessory.None) 
      { 
       thisCell.Accessory = UITableViewCellAccessory.Checkmark; 

       // Somehow deselect all the checkboxes in the other ro 
       for (int i = 0; i < 55; i++) 
       { 
        if (i == indexPath.Row) 
         continue; 

        var tmpRowIndex = NSIndexPath.FromRowSection(i, indexPath.Section); 
        var otherCell = tableView.CellAt(tmpRowIndex); 

        if (otherCell == null) 
         break; 
        else 
         otherCell.Accessory = UITableViewCellAccessory.None; 
       } 
      } 
      else 
      { 
       thisCell.Accessory = UITableViewCellAccessory.None; 
      } 
     } 
    } 
相關問題