本文實(shí)例為大家分享了iOS實(shí)現(xiàn)折疊單元格的具體代碼,供大家參考,具體內(nèi)容如下
思路
點(diǎn)擊按鈕或cell單元格來(lái)進(jìn)行展開(kāi)收縮, 同時(shí)使用一個(gè)BOOL值記錄單元格展開(kāi)收縮狀態(tài)。根據(jù)BOOL值對(duì)tableView的高度和button的image進(jìn)行實(shí)時(shí)變更。
注意點(diǎn):
在執(zhí)行- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath( 點(diǎn)擊當(dāng)前單元格)方法時(shí),收縮單元格,顯示當(dāng)前點(diǎn)擊的單元格的內(nèi)容。這一步驟的實(shí)現(xiàn)是對(duì)存儲(chǔ)單元格內(nèi)容的可變數(shù)組進(jìn)行更改。
代碼
//ViewController.h 中 #import@interface ViewController : UIViewController @property UITableView *tableView; @property UIButton *button; @property NSMutableArray *imageViewArr; @property NSMutableArray *labelArr; @property BOOL select; //記錄單元格展開(kāi)收縮狀態(tài) @end