UA-17470720-3

Jump to content


Photo
- - - - -

Manipulating the Detail View of a SCSelectionCell


  • Please log in to reply
1 reply to this topic

#1 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 10 November 2015 - 12:18 PM

Hi,

 

If I have an SCSelectionCell that allows multiple selections, how can I make two of the items in the detail view be mutually-exclusive?

 

So if I have:

 

Selection 1

Selection 2

Selection 3

Selection 4

Selection 5

 

If Selection 2 is checked and Selection 1 is already checked, Selection 1 becomes unchecked (and vice-versa). Other than that, any combination of the five selections are allowed.

 

I think maybe this is the starting point, but I am not sure where to take it from there.

 

selCell.cellActions.detailModelConfigured = ^(SCTableViewCell* cell, NSIndexPath* indexPath, SCTableViewModel* detailModel)
{
  detailModel.cellActions.willSelect = ^BOOL(SCTableViewCell* chosenCell, NSIndexPath* chosenIndexPath)
  {
  }

}

 

Thanks...

 

Bruce

 



#2 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 11 November 2015 - 03:44 AM

So this appears to work....

 

selCell.cellActions.detailModelConfigured = ^(SCTableViewCell* cell, NSIndexPath* indexPath, SCTableViewModel* detailModel)
{
  detailModel.cellActions.willSelect = ^BOOL(SCTableViewCell* chosenCell, NSIndexPath* chosenIndexPath)
  {
    SCSelectionSection* selectionSection = (SCSelectionSection*)chosenCell.ownerSection;
    BOOL zeroSelected = [selectionSection.selectedItemsIndexes containsObject:@(0)];
    BOOL oneSelected = [selectionSection.selectedItemsIndexes containsObject:@(1)];
    if ((chosenIndexPath.row == 0) && !zeroSelected)
    {
      //first item is about to be selected, so deselect second item
      [selectionSection.selectedItemsIndexes removeObject:@(1)];
      [chosenCell.ownerTableViewModel.tableView reloadData];
    }
    else if ((chosenIndexPath.row == 1) && !oneSelected)
    {
      //second item is about to be selected, so deselect first item
      [selectionSection.selectedItemsIndexes removeObject:@(0)];
      [chosenCell.ownerTableViewModel.tableView reloadData];
    }
    return TRUE;
  };
};


  • Tarek likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users