大綱
一、多個(gè)自定義單元格
步驟:
1.自定義類型
2.Cell重用標(biāo)識(shí)符
3.Cell上控件的關(guān)聯(lián)
二涨薪、tableView的展開(kāi)與閉合
步驟:
1.將被點(diǎn)擊的區(qū)頭bool取反
2.更新區(qū)中的行數(shù)
2.1 方法1(效率低):reloadData:更新表中所有的數(shù)據(jù)
2.2 方法2(效率高):reloadSections:刷新某個(gè)區(qū)的數(shù)據(jù)
3.根據(jù)bool值,刷新相應(yīng)的區(qū)潜支。
4.處理圖片旋轉(zhuǎn)
刷新表時(shí)蒸矛,自定義區(qū)頭方法會(huì)再次被執(zhí)行,因此闽颇,可以在此方法中設(shè)置圖片的旋轉(zhuǎn)
圖片旋轉(zhuǎn):
自定義區(qū)頭方法中處理
tipImgView.transform
小提示:C語(yǔ)言中的bool數(shù)組
BOOL _flagArray[5];//[no,no,no,no,no];
三盾戴、刪除
步驟:
1.點(diǎn)擊按鈕,讓表進(jìn)入編輯狀態(tài)
2.設(shè)置編輯風(fēng)格(如果是刪除兵多,不需要設(shè)置)
3.提交編輯
3.1 刪除數(shù)據(jù)源
3.2 創(chuàng)建單元格索引
3.3 存到數(shù)組中
正文
一尖啡、多個(gè)自定義單元格
步驟:
1.類型
2.重用標(biāo)識(shí)符
3.關(guān)聯(lián)
項(xiàng)目:TableView_MoreCustomStyleCell0406
1.1
2.1
2.2
3.1
3.2
重點(diǎn):
3.3
二、tableView的展開(kāi)與閉合
項(xiàng)目:TableView_OpenCloseDelete0406
步驟:
1.將被點(diǎn)擊的區(qū)頭bool取反
2.更新區(qū)中的行數(shù)
2.1 方法1(效率低):reloadData:更新表中所有的數(shù)據(jù)
2.2 方法2(效率高):reloadSections:刷新某個(gè)區(qū)的數(shù)據(jù)
3.根據(jù)bool值剩膘,刷新相應(yīng)的區(qū)衅斩。
4.處理圖片旋轉(zhuǎn)
刷新表時(shí),自定義區(qū)頭方法會(huì)再次被執(zhí)行怠褐,因此畏梆,可以在此方法中設(shè)置圖片的旋轉(zhuǎn)
圖片旋轉(zhuǎn):
在自定義區(qū)頭方法中處理
tipImgView.transform
小提示:C語(yǔ)言中的bool數(shù)組
BOOL _flagArray[5];//[no,no,no,no,no];
源碼:
#pragma mark - 區(qū)頭按鈕點(diǎn)擊事件 展開(kāi)/閉合
//1.將被點(diǎn)擊的區(qū)頭bool取反
_flagArray[sender.tag] = !_flagArray[sender.tag];
//2.更新區(qū)中的行數(shù)
//2.1 方法1(效率低):reloadData:更新表中所有的數(shù)據(jù)
// [_tableView reloadData];
//2.2 方法2(效率高):reloadSections:刷新某個(gè)區(qū)的數(shù)據(jù)
//將刷新區(qū)的索引放入索引集合
//3.根據(jù)bool值,刷新相應(yīng)的區(qū)。
NSArray *array = [_totalArr objectAtIndex:section];
return array.count;
刷新順序:
設(shè)置每個(gè)區(qū)的行數(shù)section4
設(shè)置每個(gè)區(qū)的行數(shù)section0
設(shè)置每個(gè)區(qū)的行數(shù)section1
設(shè)置每個(gè)區(qū)的行數(shù)section2
設(shè)置每個(gè)區(qū)的行數(shù)section3
設(shè)置單元格內(nèi)容(0,2)
設(shè)置單元格內(nèi)容(0,3)
設(shè)置單元格內(nèi)容(0,4)
設(shè)置單元格內(nèi)容(1,0)
設(shè)置單元格內(nèi)容(1,1)
設(shè)置單元格內(nèi)容(1,2)
設(shè)置單元格內(nèi)容(1,3)
設(shè)置單元格內(nèi)容(1,4)
設(shè)置單元格內(nèi)容(2,0)
設(shè)置單元格內(nèi)容(2,1)
自定義區(qū)頭section0
自定義區(qū)頭section1
自定義區(qū)頭section2
處理圖片旋轉(zhuǎn)
//4.處理圖片旋轉(zhuǎn)
//刷新表時(shí)奠涌,自定義區(qū)頭方法會(huì)再次被執(zhí)行宪巨,因此,可以在此方法中設(shè)置圖片的旋轉(zhuǎn)
//4.1 旋轉(zhuǎn)90度
if (_flagArray[section] == YES)
{
tipImgView.transform = CGAffineTransformMakeRotation(M_PI_2);
}
//4.2 恢復(fù)
else
{
tipImgView.transform = CGAffineTransformIdentity;
}
三铣猩、刪除
步驟:
1.點(diǎn)擊按鈕揖铜,讓表進(jìn)入編輯狀態(tài)
2.設(shè)置編輯風(fēng)格(如果是刪除,不需要設(shè)置)
3.提交編輯
3.1 刪除數(shù)據(jù)源
3.2 創(chuàng)建單元格索引
3.3 存到數(shù)組中
#pragma mark - 單元格的刪除
//1.點(diǎn)擊按鈕达皿,讓表進(jìn)入編輯狀態(tài)
- (void)deleteClick:(UIBarButtonItem *)item
{
[_tableView setEditing:!_tableView.editing animated:YES];
item.title = _tableView.editing == NO ? @"刪除" : @"完成";
}
//2.設(shè)置編輯風(fēng)格(如果是刪除天吓,不需要設(shè)置)
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
//3.提交編輯
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//1.刪除數(shù)據(jù)源
NSMutableArray *mArray = [_totalArr objectAtIndex:indexPath.section];
[mArray removeObjectAtIndex:indexPath.row];
//2.創(chuàng)建單元格索引
NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
//3.存到數(shù)組中
NSArray *array = [NSArray arrayWithObjects:cellIndexPath, nil];
//IndexPaths:存放索引的數(shù)組
//刪除單元格時(shí),系統(tǒng)會(huì)刷新表
[tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
}