[英]UICOllectionview, scrolling to first cell that contains in its title an NSString
I have a uicollectionview hosting a number of cells, each cell has a title on it. 我有一个uicollectionview托管多个单元格,每个单元格上都有一个标题。 the same collectionview can have multiple cells that have the same title.
同一collectionview可以包含多个具有相同标题的单元格。 I need to grammatically scroll the collectionview to the first occurrence of a cell which has title = user selection.
我需要在语法上将collectionview滚动到具有title =用户选择的单元格的首次出现。
How can I achieve that? 我该如何实现?
Loop through you data source and find the first object and call then call collection views scrolltoIndexPath method. 遍历您的数据源,找到第一个对象,然后调用,然后调用集合视图scrolltoIndexPath方法。
__block NSIndexPath* indexPath = nil;
[yourDataSource enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:title]) {
indexPath = [NSIndexPath indexPathForRow:idx inSection:0];
*stop = YES;
}
}];
if (indexPath) {
//set the scroll position accordingly
[collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.