![](/img/trans.png)
[英]collectionview cell is not visible even after delegate methods are getting called
[英]Collectionview Cell Delegate method not called on scrollToItemAtIndexPath?
我在控制器的viewDidLayoutSubviews
部分中使用scrollToItemAtIndexPath
,以允许我将用户滚动到特定的单元格。
我的单元格作为cellForItemAtIndexPath
一部分加载时,应该对其参数进行网络调用
问题是将打印语句放在cellForItemAtIndexPath
似乎从未被调用过? 造成冲突的原因是什么?如何解决冲突? 代码如下:
- (void)viewDidLayoutSubviews {
CDCChannelCollectionView *scrollView;
if (self.view == [self mixMonitorView]) {
scrollView = [[self mixMonitorView] scrollView];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection: self.selectedChanIndex];
[scrollView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CDCChannelStrip *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
if (self.view == self.mixMonitorView) {
NSInteger chanInt = indexPath.section;
NSNumber *chanNum = [NSNumber numberWithInteger:chanInt];
NSNumber *chanNameNumber = [NSNumber numberWithInteger:chanInt + 1];
NSString *chanName = [NSString stringWithFormat:@"CH %@", chanNameNumber];
cell.channelNumber = chanInt;
cell.channelName.text = chanName;
[self getParameters:(chanNum)];
[self.mixMonitorView setChannelsStripToType:(cell)];
cell.clipsToBounds = YES;
return cell;
}
}
数据源方法将调用重新加载集合视图。
试试下面
[yourCollectionViewName reloadData];
scrollToItemAtIndexPath
将不会调用数据源方法,除非它滚动到滚动前不可见的collectionViewCell
。 如果滚动到已经可见的单元格,则需要调用reloadData
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.