我正在使用这一行
[self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
在cellForItemAtIndexPath方法中,以编程方式选择集合视图中的项目并且它正在工作,问题是它只有在我触摸集合视图后才能工作。如何在加载集合视图后立即使其工作?
答案 0 :(得分:0)
在viewDidLoad或viewDidAppear中调用它。
如果您知道要在加载时选择的位置,可以使用以下命令创建NSIndexPath对象:[NSIndexPath indexPathForRow:inSection:]
例如:NSIndexPath *myIndex = [NSIndexPath indexPathForRow:0 inSection:0];