Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何立即调用selectItemAtIndexPath_Ios_Iphone_Uicollectionview - Fatal编程技术网

Ios 如何立即调用selectItemAtIndexPath

Ios 如何立即调用selectItemAtIndexPath,ios,iphone,uicollectionview,Ios,Iphone,Uicollectionview,我在用这条线 [self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone]; 在cellForItemAtIndexPath方法中,要以编程方式在collection视图中选择一个项目并使其工作,问题是它只有在我触摸collection视图后才能工作。如何在集合视图加载后立即使其工作?在viewDidLoad或ViewDid

我在用这条线

[self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];

在cellForItemAtIndexPath方法中,要以编程方式在collection视图中选择一个项目并使其工作,问题是它只有在我触摸collection视图后才能工作。如何在集合视图加载后立即使其工作?

在viewDidLoad或ViewDidDisplay中调用它

如果知道加载时要选择的位置,可以使用以下命令创建nsindepath对象:
[nsindepath indexPathForRow:instation:


例如:
nsindepath*myIndex=[nsindepath-indexPathForRow:0第1节:0]

在ViewDidDisplay中调用它。但是我需要我要选择的项的索引。嗨,我通过执行一些验证知道我要在cellForItemAtIndexPath中选择的indexPath,这就是为什么我将它放在这个方法中CellForRowaItemIndex方法在视图加载时对每个集合项调用一次。因此,如果您将某些内容放在那里,您应该会看到UIcollectionView上加载时选择的最后一项。