RemembersLastFocusedIndexPath not working on UICollectionView

I have a collection view with a standard horizontal layout. After presenting the view controller and then rejecting it, the reset collection view will focus on the first cell, although the last focused cell was not like that.

I have installed

self.collectionView.remembersLastFocusedIndexPath = YES;

What is strange is that this only happens when I click the view controller on my navigation controller.

So if i do

[self.navigationController pushViewController:controller animated:YES];

and then let go, remembersLastFocusedIndexPathit’s not working properly.

However, if I:

[self presentViewController:controller animated:YES completion:nil];

Then it works as expected.

Any idea why it won't work through the navigation controller?

+4
source share
4 answers

, , preferredFocusView viewController :

override weak var preferredFocusedView: UIView? {
    return collectionView
}

, LastFocusedIndexPath.

+5

, Data() viewWillAppear collectionView TableView. rememberedFocus ( )

+2

. , , remembersLastFocusedIndexPath false.

UICollectionViewDelegate: func indexPathForPreferredFocusedViewInCollectionView(collectionView: UICollectionView) -> NSIndexPath?

:

UICollectionView, FocusedView UIFocusEnvironment. LastFocusedIndexPath YES, , , .

remembersLastFocusedIndexPath false .

+1

. func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) func collectionView(collectionView: UICollectionView, canFocusItemAtIndexPath indexPath: NSIndexPath) -> Bool

0

Source: https://habr.com/ru/post/1609053/


All Articles