【发布时间】:2016-10-13 06:21:13
【问题描述】:
我在 UITableviewCell 中使用了 UICollectionView,一切正常,仍在加载集合视图并显示其单元格,但加载集合视图后,当点击集合视图单元格时,我无法获取集合视图的“didSelectItemAtIndexPath”委托方法。
我的表格视图具有静态单元格,我将集合视图放在该单元格中
还要在上面定义委托和数据源
这是我的代码,调用了数据源方法但未调用委托
#pragma mark - collectionView data source
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 10;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collCell" forIndexPath:indexPath];
UIImageView *imgDocCell = (UIImageView *)[cell viewWithTag:100];
imgDocCell.image = self.imgFileToChart;
cell.layer.borderWidth=1.0f;
cell.layer.borderColor=commonThemeColor.CGColor;
return cell;
}
#pragma mark - collectionView delegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",indexPath);
}
【问题讨论】:
-
collectionView data source代码添加在哪里? -
我认为它采用 tableview 委托方法。在 tableview 委托方法中放置断点并检查它
-
@Mr.Bista 在我的 tableview 控制器中
-
只需检查它,如果它采用 tabelview 委托方法,则禁用该单元格的用户交互,然后它为 collectionview 委托工作
-
@jecky:我会试试的,谢谢
标签: ios objective-c uitableview uicollectionview uicollectionviewcell