我有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];
使用委託伴侶。 –