我注意到iOS在UITableViewCell
内使用UICollectionView
时非常的平均。我试图实现的目标是在UITableViewCell
内部收集图像(UICollectionView
方法)。我试图模仿Facebook发布的风格,我想,他们有一个UITableView
,定制细胞等,但这里的问题...UITollectionView里面的UITableViewCell
我已经成功地把UICollectionView
的UITableViewCell
内,它的工作正确完美,没有问题,一切都很好,可点击等等。但是,我想修改我的代码,提取UICollectionViewDataSource
& UICollectionViewDelegate
到单独的文件中重复使用它们,并且具有更少的代码在Main View Controller
,正是在这里,当我噩梦开始,我不知道是什么原因,如果我使用单独的文件iOS循环单元格的配置。例如:
-(void)configureCell:(UICollectionViewCell*)customCell atIndexPath:(NSIndexPath*)indexPath;
上述方法它被称为对过程的两个部分:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *identifier = [self retrieveIdentifierForIndexPath:indexPath];
UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:identifier];
[self configureCell:myCell atIndexPath:indexPath];
[cell setNeedsLayout];
[cell layoutIfNeeded];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize].height;
return height;
}
上述方法它调用使用自动版式来计算行高我在这里阅读上一个帖子计算器(不记得交:()
它被计算等等,另一种方法调用“configureCell
”方法后的高度:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *rowName = [self retrieveIdentifierForIndexPath:indexPath];
PostDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rowName forIndexPath:indexPath];
//PreCondition
if([rowName isEqualToString:@"LoadingRow"]){
return cell;
}
// Configure the cell...
[self configureCell:cell atIndexPath:indexPath withImages:YES];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
当调试器启动时,该方法configureCell:atIndexPath:
它被称为一遍又一遍又一遍。这是第二次发生这种情况。这是否意味着我不能“分开”DataSource
?或它是不可能的在UITableViewCell
内添加UICollectionView
。或者,我是否使用了一种不好的方法?有没有办法做到这一点?
我对此很困惑......
谢谢各位!
我有同样的问题..到目前为止还没有得到解决方案。 – 2014-09-24 06:31:30
通过整个单元配置来确定行高是不好的。 – 2014-09-24 15:53:34
不知道如何计算身高:/我看到的所有例子都建议这么做 – NemesisDoom 2014-09-24 19:41:04