I have a
UICollectionView of custom UICollectionViewCell subclasses, each with a UILabel and a UIButton. I want to make use of the great default focus behavior of the UIButton (since UICollectionViewCells don't have any default focus behavior), so I override the preferredFocusedView property of the UICollectionViewCell subclass to return the UIButton:@IBOutlet weak var button:UIButton!
@IBOutlet weak var textLabel:UILabel!
override var preferredFocusedView:UIView?
{
get {
return self.button
}
}
override func canBecomeFocused() -> Bool
{
return true
}When I do this, I'm unable to move the selection to the next
UICollectionViewCell. The context object of collectionView(_:didUpdateFocusInContext:withAnimationCoordinator:) reports that the previous and next NSIndexPaths are always (0,0).If I instead return
self or self.textLabel from preferredFocusView and do custom focus appearance changes (like changing the backgroundColor of the UICollectionViewCell), I'm able to move focus around the UICollectionView without problem. collectionView(_:canFocusItemAtIndexPath:) has not been overridden. Is there some default behavior of focus in the UIButton that I'm overlooking?