版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、繼續(xù)介紹一個有用的TableView中全選單元格的例子,里面的方法可以用在閱讀器中用 戶對閱讀內(nèi)容來源的選擇上,如圖所示:運(yùn)營高令全選運(yùn)營高宇取消核心代碼如下:objc view plaincopy1.2.3.4.5.6.-(void)viewDidLoadsuper viewDidLoad;/創(chuàng)建表視圖_table_table = UITableView allocinitWithFrame:CGRectMake(0, 64, 320, 500) s tyle:UITableViewStylePlain;7.8.9.10._table.delegate = self;_table.dataS
2、ource = self;self .view addSubview:_table;11.12.13.14./將字典NO- checked裝入可變數(shù)組中,來控制單元格左邊對勾視圖 _contacts = NSMutableArray array;for (int i = 0; i 10; i+) NSMutableDictionary *dic = NSMutableDictionary dictionary;15.16.17.18.19.20.21.22.23.24.25.1.2.3.4.5.6.dic setValue:NO forKey:checked;_contacts addObje
3、ct:dic;/創(chuàng)建屏幕左上方的全選按鈕_button = UIButton buttonWithType:UIButtonTypeRoundedRect;_button setTitle :全選forState:UIControlStateNormal;_button.frame = CGRectMake(10, 10, 100, 50);_button addTarget:self action:selector(allSelect:) forControlEvents:UIControlEventTouchUpInside;self.view addSubview:_button; ob
4、jc view plaincopy/全選按鈕的觸發(fā)事件-(void)allSelect:(UIButton*)sender將表視圖的所有的單元格放在數(shù)組里NSArray *anArrayOfIndexPath = NSArray arrayWithArray:_table indexPathsForVisibleRows;7.8.9.10.11.12.13.14.15.16.17.)18.19.20.21.22.23.24.25.26./27.ifh:indexPath;for (int i = 0; i anArrayOfIndexPath count; i+) /得到表視圖的indexPa
5、thNSIndexPath *indexPath= anArrayOfIndexPath objectAtIndex:i;/創(chuàng)建每個單元格,LTableViewCell *cell = (LTableViewCell*)_table cellForRowAtIndexPatNSUInteger row = indexPath row;NSMutableDictionary *dic = _contacts objectAtIndex:row;/判斷當(dāng)前按鈕的狀態(tài)是全選還是取消,設(shè)置不同的標(biāo)記if (UIButton*)sender titleLabel text isEqualToString
6、:全選dic setObject:伊YES forKey:checked;cell setChecked:YES;else dic setObject:伊NO forKey:checked;cell setChecked:NO;兩種狀態(tài)的切換(UIButton*)sender titleLabel text isEqualToString:全選)28.29.30.31.32.33.34.35.36.37.38.39.40.41.for (NSDictionary *dic in _contacts) dic setValue:YES forKey:checked; (UIButton*)sen
7、der setTitle:取消 forState:UIControlStateNormal;elsefor (NSDictionary *dic in _contacts) dic setValue:NO forKey:checked;(UIButton*)sender setTitle:全選forState:UIControlStateNormal; objc view plaincopy1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.-(UITableViewCell *)tableView:(UITableView *)t
8、ableView cellForRowAtIndexPat h:(NSIndexPath *)indexPathstatic NSString * identifier = Cell;/創(chuàng)建單元格LTableViewCell * cell = tableView dequeueReusableCellWithIdentifier:ide ntifier;if (cell = nil) cell = LTableViewCell allocinitWithStyle:UITableViewCellStyleDefa ult reuseIdentifier:identifier;NSUIntege
9、r row = indexPath row;NSMutableDictionary *dic = _contacts objectAtIndex:row;if (dic objectForKey:伊checked isEqualToString:NO) dic setObject:NO forKey:checked;cell setChecked:NO;else dic setObject:YES forKey:checked;cell setChecked:YES;return cell;23.objc view plaincopy1.2.3.4.5.-(void)tableView:(UI
10、TableView *)tableView didSelectRowAtIndexPath:(NSIndexP ath *)indexPathtableView deselectRowAtIndexPath:indexPath animated:YES;LTableViewCell *cell = (LTableViewCell*)tableView cellForRowAtIndexPath6.7.8.9.10.11.12.13.14.15.16.17.18.19.:indexPath;NSUInteger row = indexPath row;NSMutableDictionary *d
11、ic = _contacts objectAtIndex:row;/創(chuàng)建單元格左邊的打鉤視圖if (dic objectForKey:伊checked isEqualToString:NO) dic setObject:YES forKey:checked;cell setChecked:YES;else dic setObject:NO forKey:checked;cell setChecked:NO;在 LTableViewCell 中objc view plaincopy1.2.3.4.5.6.7.8.5.09.10.11./用checked來判斷是否加上對勾視圖-(void)setChecked:(BOOL)checkedif (checked)m_checkImageView.image = UIImage imageNamed:Selected.png;self.backgroundView.backgroundColor = UIColor colorWithRed:223.0/25 green:230.0/255.0 blue:250.0/255.0 alpha:1.0;else12.13.14.15.16.17.18.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度出院患者出院后康復(fù)護(hù)理服務(wù)協(xié)議書范本4篇
- 乙方負(fù)責(zé)甲方2024年度廣告投放的合同
- 2025年度時尚潮流門面租賃管理服務(wù)協(xié)議4篇
- 二零二四年度藝術(shù)品捐贈合同2篇
- 2025年度電梯安裝與節(jié)能改造設(shè)計合同4篇
- 二零二四年熟食加盟店運(yùn)營管理合作協(xié)議范本3篇
- 二零二五年度二手房買賣稅收優(yōu)惠協(xié)議3篇
- 二零二五年度撫養(yǎng)權(quán)變更及子女財產(chǎn)權(quán)益保障協(xié)議3篇
- 二零二四年度智能家居系統(tǒng)安裝工程合同2篇
- 二手房租賃協(xié)議法律文檔
- 開展課外讀物負(fù)面清單管理的具體實(shí)施舉措方案
- 2025年云南中煙工業(yè)限責(zé)任公司招聘420人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025-2030年中國洗衣液市場未來發(fā)展趨勢及前景調(diào)研分析報告
- 2024解析:第三章物態(tài)變化-基礎(chǔ)練(解析版)
- 北京市房屋租賃合同自行成交版北京市房屋租賃合同自行成交版
- 《AM聚丙烯酰胺》課件
- 系統(tǒng)動力學(xué)課件與案例分析
- 《智能網(wǎng)聯(lián)汽車智能傳感器測試與裝調(diào)》電子教案
- 客戶分級管理(標(biāo)準(zhǔn)版)課件
- GB/T 32399-2024信息技術(shù)云計算參考架構(gòu)
- 固定資產(chǎn)盤點(diǎn)報告醫(yī)院版
評論
0/150
提交評論