1.利用reloadRowsAtIndexPaths:withRowAnimation:來動態改變cell的高度
UITableView的- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
這一方法會重新加載所指定indexPaths中的UITableViewCell實例,因為重新加載cell所以會請求這個UITableView實例的data source來獲取新的cell;這個表會用動畫效果讓新的cell進入,並讓舊的cell退出。
會調用UITableViewDataSource協議中的所有方法來更新數據源,其中調用 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
只會調用所需更新的行數,來獲取新的cell,
注意:此時該cell的- (void)setSelected:(BOOL)selected animated:(BOOL)animated將被調用,所設置的selected為NO;
[tableView beginUpdates];
if (newCount<=0) {
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationLeft];
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationLeft];
[tableView endUpdates];
這兩個方法,是配合起來使用的,標記了一個tableView的動畫塊。
分別代表動畫的開始開始和結束。
兩者成對出現,可以嵌套使用。
一般,在添加,刪除,選擇 tableView中使用,並實現動畫效果。
在動畫塊內,不建議使用reloadData方法,如果使用,會影響動畫。
插入指定的行,
在執行該方法時,會對數據源進行訪問(分組數據和行數據),並更新可見行。所以,在調用該方法前,應該先更新數據源
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
插入分組到制定位置
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
插入一個特定的分組。如果,指定的位置上已經存在了分組,那么原來的分組向后移動一個位置。
刪除制定位置的分組
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
刪除一個制定位置的分組,其后面的分組向前移動一個位置。
移動分組
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection
移動原來的分組從一個位置移動到一個新的位置。如果,新位置上若存在某個分組,那這某個分組將會向上(下)移動到臨近一個位置。該方法,沒有動畫參數。會直接移動。並且一次只能移動一個分組。