一: 獲取當前點擊cell
一般collectionView 或者 tableview都有自帶的點擊函數(shù)碰逸,如下:
1. collectionView
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//一般情況润脸,cell不是自定義
UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath]; //即為要得到的cell
//自定義的cell
TitleViewCell * cell = (TitleViewCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];//即為要得到的cell
}
2,tableView
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//非自定義cell
UITableViewCell * cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
//自定義cell
NewsTableViewCell * cell = (NewsTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
}
二: 更新cell
1. 更新全部數(shù)據(jù)
UICollectionView 與 UITableView類似沿猜,都可以使用 reloadData 方法來進行所有 cell內(nèi)容的更新掸驱,reloadData 過程沒有默認的動畫過程
2. 更新特定 cell 中的數(shù)據(jù)
UICollectionView
可以采用 reloadItemsAtIndexPaths方法
[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
傳入?yún)?shù)就是要刷新的 cell 所在的 indexPath組成的數(shù)組工碾,但 reloadItemsAtIndexPath默認會有一個動畫的過程庵楷,cell內(nèi)容更新的瞬間會出現(xiàn)原內(nèi)容與新內(nèi)容重疊的情況啦逆,使用如下方式取消該動畫即可 :
[UIView performWithoutAnimation:^{
[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
}];
UITableView
UITableView 的 reloadSections方法也有同樣的情況 :
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];