Texture icon indicating copy to clipboard operation
Texture copied to clipboard

Preselect cell in ASCollectionNode

Open just-poster opened this issue 5 years ago • 1 comments

Xcode: 11.7 Texture: 3.0

Hi, I faced the problem when I was trying to preselect a specific cell ASCollectionNode. Code example for nodeForItemAtIndexPath:

func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode {
        let text = dataSource[indexPath.item]
        let cellNode = CellNode(text: text)

        cellNode.isSelected = true
        
        return cellNode
    }

Code example for isSelected:

override var isSelected: Bool {
        didSet {
            borderWidth = isSelected ? 3.0 : 0.0
            borderColor = UIColor.red.cgColor
        }
    }

The above didSet is called twice: 1) after cellNode.isSelected = true and is setting everything correctly 2) but after second call from method:

- (void)__setSelectedFromUIKit:(BOOL)selected;
{
  // Note: Race condition could mean redundant sets. Risk is low.
  if (ASLockedSelf(_selected != selected)) {
    _suspendInteractionDelegate = YES;
    self.selected = selected;
    _suspendInteractionDelegate = NO;
  }
}

selected is set to NO.

Can anyone tell me what am I doing incorrectly?

just-poster avatar Oct 21 '20 08:10 just-poster

I'm facing the same problem

phamtu24impl avatar Apr 21 '22 09:04 phamtu24impl