我在我的控制器的viewDidLayoutSubviews
部分使用scrollToItemAtIndexPath
來允許我將用戶滾動到特定的單元格。Collectionview單元格委託方法不在scrollToItemAtIndexPath上調用?
我的細胞都應該當加載作爲cellForItemAtIndexPath
部分的問題,使他們的PARAMS網絡電話是把一個print語句在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;
}
}
您需要滾動到所選索引的權限? – CodeChanger
是滾動不是問題,它工作正常,它不調用正確的單元格委託方法後的事實 – jcad
是的bcus你做錯了調用這樣做'NSIndexPath * indexPath = [NSIndexPath indexPathForItem:self.selectedChanIndex inSection:0 ];' – CodeChanger