我注意到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