Cell復(fù)用
[tableView dequeueReusableCellWithIdentifier:@"cell"];
從復(fù)用池里取出可以復(fù)用的Cell(若沒有,則取出來的是nil)
[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
從復(fù)用池里取可以復(fù)用的Cell,如果沒有,則通過重用標(biāo)識符自動創(chuàng)建對應(yīng)的Cell
一些常用的TableView的API
[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom]
刪除Cell,可以選擇刪除的動畫
[tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
插入Cell,可以選擇動畫
刪除或者插入Cell,一定要同步添加數(shù)據(jù)源
只會局部刷新數(shù)據(jù),如果遇到一些奇奇怪怪的bug,可以嘗試通過reloadData
解決
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
[tableView reloadData];
});
});
- 選中Cell后自動恢復(fù)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- 自定義Cell在
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;
方法里
tableView重點(diǎn): 數(shù)據(jù)驅(qū)動UI改變