【问题标题】:UICOllectionview, scrolling to first cell that contains in its title an NSStringUICollectionview,滚动到标题中包含 NSString 的第一个单元格
【发布时间】:2013-11-06 04:27:42
【问题描述】:
我有一个 uicollectionview 托管多个单元格,每个单元格上都有一个标题。
同一个collectionview 可以有多个具有相同标题的单元格。
我需要以语法方式将 collectionview 滚动到第一个出现 title = user selection 的单元格。
我怎样才能做到这一点?
【问题讨论】:
标签:
ios
iphone
objective-c
uicollectionview
uicollectionviewcell
【解决方案1】:
遍历您的数据源并找到第一个对象并调用然后调用集合视图 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];
}