我有UI,如附图所示。它有两个组件,主要是UICollectionView和UITableView。UICollectionView更新特定单元格的单元格内容
我试图当用户从任何的UITableView细胞在这里实现,我想更新顶部CollectionViewCell。
我到目前为止做了什么。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(![self.selectedIndexPath isEqual:indexPath]){
UITableViewCell* uncheckCell = [tableView cellForRowAtIndexPath:self.selectedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
UITableViewCell* cellCheck = [tableView cellForRowAtIndexPath:indexPath];
cellCheck.accessoryType = UITableViewCellAccessoryCheckmark;
self.selectedIndexPath = indexPath;
NSIndexPath *collectionIndex = [NSIndexPath indexPathForItem:0 inSection:self.currentPage];
//TODO:Find Correct Cell
UICollectionViewCell *cellToUpdate = [self.collectionView cellForItemAtIndexPath:collectionIndex];
for (UIView *subView in [cellToUpdate.contentView subviews]) {
if ([subView isKindOfClass:[CustomView class]]) {
CustomView *infoView = (CustomView *)subView;
[infoView updateInfoWithIndex:indexPath.row];
}
}
[self.collectionView reloadData];
}
我觉得我在做下面这行错了。不知道是什么?
NSIndexPath *collectionIndex = [NSIndexPath indexPathForItem:0 inSection:self.currentPage];
使用委托伴侣。 –