Texture
Texture copied to clipboard
Preselect cell in ASCollectionNode
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?
I'm facing the same problem