所謂NSIndexPath,主要用來標識cell在列表中的坐標位置,其有兩個屬性:section、row,section是用來標識cell處于第幾個section中,row是用來說明cell在該section中的第幾行。
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
[_mainCollectionView reloadItemsAtIndexPaths:@[indexPath]];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:3];
[_mainCollectionView reloadSections:indexSet];
傳入參數就是要刷新的cell所在的indexPath組成的數組。但,reloadItemsAtIndexPath默認會有一個動畫的過程,cell內容更新的瞬間會出現原內容與新內容重疊的情況。那么使用如下方式取消該動畫即可:[UIView performWithoutAnimation:^{ [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];}];UITableView
UITableView的reloadSections方法也有同樣的情況:
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];而使用reloadData進行全部cell的更新,則沒有這個默認的動畫過程。
新聞熱點
疑難解答