【发布时间】:2017-06-29 10:38:43
【问题描述】:
我在控制器的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;
}
}
【问题讨论】:
-
您需要滚动到选定的索引吗?
-
是的,滚动不是问题,它工作正常,事实上它在之后没有正确调用单元格委托方法
-
是的,因为你打错电话了,像这样
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.selectedChanIndex inSection:0]; -
collectionview 是由部分而不是项目组成的,你的代码什么都不做
-
你的代码应该在 cellforItemIndexpath 中抛出错误,你还有更多的代码吗??
标签: ios objective-c uicollectionview