Ale*_*rik 6 uitableview ios uicollectionview
我无法解决下一个问题.
我想显示20个表格单元格,每个单元格包含一个唯一的UICollectionView.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *package=[_packageList objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"package";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UICollectionView *cellImageCollection=(UICollectionView *)[cell viewWithTag:9];
cellImageCollection.restorationIdentifier=[NSString stringWithFormat:@"%li", (long)indexPath.row, nil];
cellTracking.text=[NSString stringWithFormat:@"Row #%li",(long)indexPath.row];
return cell;
}
-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
int row=[collectionView.restorationIdentifier intValue];
return [[[_packages objectAtIndex:row] valueForKey:@"imageGallery"] count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
int row=[collectionView.restorationIdentifier intValue];
NSString *imgStrLink=[[[_packages objectAtIndex:row] valueForKey:@"imageGallery"] objectAtIndex:indexPath.row];
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageID" forIndexPath:indexPath];
UIImageView *imageView=(UIImageView *)[cell viewWithTag:2];
imageView.image=....;
return cell;
}
Run Code Online (Sandbox Code Playgroud)
功能tableView:cellForRowAtIndexPath:被称为20倍,但collectionView:numberOfItemsInSection:与collectionView:cellForItemAtIndexPath:只有4次.如截图所示,UICollectionView每隔四行重复一次.
我的错是什么?
我也遇到了这个问题,我遇到这个问题的原因是因为tableview和collectionView的数据源和委托都是同一个父viewcontroller.
当我将collectionView的数据源和委托更改为另一个View说ParentView时,它开始为我工作,我将collectionView添加到此ParentView,然后最终添加ParentView作为单元格的conentView.
我之前的回答指出了两个很好的教程被有人说我应该在这里包含内容的基本部分(因为链接可能在将来变得无效)...但我不能这样做,因为那些是由教程所有者以及整个代码也是必不可少的:),所以现在我给出源代码的链接...
-anoop
| 归档时间: |
|
| 查看次数: |
24995 次 |
| 最近记录: |