简体   繁体   English

如何基于单元格文本获取UICollectionViewCell的indexPath?

[英]How to get indexPath of UICollectionViewCell based on cell text?

I pass the cell title label from "collection view A" to "collection view B". 我将单元格标题标签从“集合视图A”传递到“集合视图B”。 So now in collection View B, I have the cell's title label. 因此,现在在视图集B中,我具有单元格的标题标签。

In the viewDidAppear method for collection View B, I'd like to use scrollToItemAtIndexPath to scroll to the proper index containing the cell with that title label. 在集合视图B的viewDidAppear方法中,我想使用scrollToItemAtIndexPath滚动到包含带有该标题标签的单元格的正确索引。

How would I go about doing that? 我将如何去做?

Collections work like TableViews. 集合的工作方式类似于TableViews。 Most people have a backing store of data behind their collection or tableview, which is an array with data in the proper order. 大多数人在其集合或表视图的后面都有数据的后备存储,这是一个按正确顺序排列数据的数组。 Thus, when your cellForRowAtIndexPath or cellForItemAtIndexPath call is invoked, you simply stuff in the value from your backing store. 因此,当调用cellForRowAtIndexPath或cellForItemAtIndexPath调用时,您只需填充后备存储中的值即可。 If your model is the same as this you would simply search your collection view B backing store array for the label, and make note of what row it is in. 如果您的模型与此模型相同,则只需在集合视图B后备存储阵列中搜索标签,并记下它所在的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM