2017-07-25 4 views
0

Ich habe einen UITableViewController und eine Liste von Kontrollkästchen in jedem Abschnitt. Was ist der richtige Weg zuWie entferne ich Häkchen von "anderen Zeilen" in einem UITableViewController

  • Fetch die Zeilen für den Abschnitt
  • Ändern der Checkbox des Abschnitts, so dass ich mich richtig als auch meine Unterstützung Datensicht und die UX Ansicht aktualisieren?

... in anderen Worten, ich möchte nur ein Häkchen im Abschnitt 1. Ich NSIndexPath versucht, mit, aber die Eigenschaften nur gelesen werden.

enter image description here

-Code

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; 
      } 
     } 
    } 

Antwort

0

Die Art und Weise eine NSIndexPath zu erzeugen, ist in einer statischen Methode befindet ...

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; 
      } 
     } 
    } 
Verwandte Themen