简体   繁体   English

UICOllectionview,滚动到标题中包含NSString的第一个单元格

[英]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.

相关问题 UICollectionView - 滚动到第一个单元格 - UICollectionView - Scrolling to first cell 滚动到 UICollectionView 中的下一个单元格 - Scrolling to next cell in UICollectionView UICollectionView:激活,滚动到第一响应者并将其分配给远程单元 - UICollectionView: activating, scrolling to, and assigning first responder to distant cell 滚动时获取UICollectionView的第一个单元格/项-iOS - Getting first Cell/Item of UICollectionView while scrolling - iOS uicollectionview滚动更改单元格索引路径 - uicollectionview scrolling change cell indexpath 选择单元格时 UICollectionView 正在滚动 - UICollectionView is scrolling when selecting a cell iOS中的UICollectionView单元格滚动问题 - UICollectionView cell scrolling issue in ios 在读出第一个单元格的标签之前,如何让 UICollectionView 读取它自己的可访问性标签? - How to make a UICollectionView read its own accessibility label before reading out its first cell's label? iOS swift UICollectionView 在滚动超过第一个屏幕后失去单元格约束 - iOS swift UICollectionView loses cell constraints after scrolling past first screen full 在包含UICollectionView和UIImageView的主视图中垂直滚动 - Vertical scrolling in a master view that contains UICollectionView and UIImageView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM