日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios基础篇(二十六)—— UITableViewCell的分组索引与标记

發(fā)布時(shí)間:2024/4/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios基础篇(二十六)—— UITableViewCell的分组索引与标记 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、表視圖的索引目錄

首先要?jiǎng)?chuàng)建一個(gè)TableView,之前有說過,這里就不詳細(xì)說了(參考前面第十四篇)。

直接貼代碼吧,

1 #import "ViewController.h" 2 3 @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>{ 4 5 UITableView *tableView; 6 7 NSArray *list;//分組標(biāo)題 8 NSDictionary *dic;//每行內(nèi)容 9 } 10 11 @end 12 13 @implementation ViewController 14 15 - (void)viewDidLoad { 16 [super viewDidLoad]; 17 // Do any additional setup after loading the view, typically from a nib. 18 CGFloat width = self.view.frame.size.width; 19 CGFloat height = self.view.frame.size.height; 20 21 tableView = [[UITableView alloc] initWithFrame:(CGRect){0,20,width,height}]; 22 tableView.dataSource = self; 23 tableView.delegate = self; 24 tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 25 [self.view addSubview:tableView]; 26 27 [self readySource]; 28 } 29 30 //在viewDidLoad方法中調(diào)用 31 - (void)readySource{ 32 33 dic = @{@"A":@[@"adhere", @"adaft", @"abase", @"alarm", @"apace"], 34 @"B":@[@"babel", @"board", @"bili", @"band"], 35 @"C":@[@"cabbages", @"crray", @"china", @"chafe", @"cocos", @"core"], 36 @"D": @[@"dabbing", @"dacca", @"dady"], 37 @"E": @[@"email", @"each", @"eager", @"ebook", @"enable", @"embalm", @"eman"], 38 @"F": @[@"fear", @"faceBook", @"float", @"flour"], 39 @"G": @[@"getter", @"gaba", @"grace", @"great", @"gracious"], 40 @"H": @[@"header", @"haber", @"habit", @"hoard"], 41 }; 42 list = dic.allKeys; 43 } 44 45 //返回分組個(gè)數(shù) 46 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 47 return [list count]; 48 } 49 50 //返回每個(gè)分組中的行數(shù) 51 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 52 //獲取分組 53 NSString *key = [list objectAtIndex:section]; 54 //獲取分組里面的數(shù)組 55 NSArray *array = [dic objectForKey:key]; 56 57 return [array count]; 58 } 59 60 - (UITableViewCell *)tableView:(UITableView *)TableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 61 62 //索引路徑 63 NSInteger section = [indexPath section]; 64 NSInteger row = [indexPath row]; 65 66 //獲取分組 67 NSString *key = [list objectAtIndex:section]; 68 69 //獲取分組里面的數(shù)組 70 NSArray *array = [dic objectForKey:key]; 71 72 //建立可重用標(biāo)識(shí)符 73 static NSString *indentifier = @"UITableViewCell"; 74 75 // NSString *indentifier = [NSString stringWithFormat:@"UITableViewCell%ld%ld",(long)indexPath.row,(long)indexPath.section]; 76 77 UITableViewCell *cell = [TableView dequeueReusableCellWithIdentifier:indentifier]; 78 if (!cell) { 79 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier]; 80 } 81 82 //設(shè)置其輔助樣式 83 cell.accessoryType = UITableViewCellAccessoryNone; 84 85 //移除所有子視圖 86 [cell.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 87 UIView *view = (UIView*)obj; 88 [view removeFromSuperview]; 89 }]; 90 91 //添加新視圖 92 UILabel *title = [[UILabel alloc] initWithFrame:(CGRect){20,10,200,30}]; 93 NSString *str = [array objectAtIndex:row]; 94 title.text = str; 95 title.font = [UIFont systemFontOfSize:20]; 96 title.textColor = [UIColor blueColor]; 97 [cell addSubview:title]; 98 99 return cell; 100 } 101 102 //獲取分組標(biāo)題 103 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 104 105 NSString *key = [list objectAtIndex:section]; 106 return key; 107 } 108 109 //給TableViewCell添加索引 110 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ 111 112 return list; 113 114 } 115 116 //點(diǎn)擊目錄 117 - (NSInteger)tableView:(UITableView *)TableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ 118 119 //獲取所點(diǎn)目錄對(duì)應(yīng)的IndexPath值 120 NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index]; 121 122 //讓Table滾動(dòng)到對(duì)應(yīng)的indexPath位置 123 [TableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 124 return index; 125 } 126 127 //設(shè)置TableViewCell行高 128 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 129 130 return 50; 131 }

效果圖:

二、可以進(jìn)行標(biāo)記的表視圖

首先要在- (UITableViewCell *)tableView:(UITableView *)TableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;方法中,把cell.accessoryType = UITableViewCellAccessoryNone;

1 //點(diǎn)擊行事件 2 - (void)tableView:(UITableView *)TableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 3 4 //獲取點(diǎn)擊行的cell 5 UITableViewCell *cell = [TableView cellForRowAtIndexPath:indexPath]; 6 7 //如果cell已經(jīng)被標(biāo)記 8 if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 9 //取消標(biāo)記 10 cell.accessoryType = UITableViewCellAccessoryNone; 11 }else 12 //反之,標(biāo)記 13 cell.accessoryType = UITableViewCellAccessoryCheckmark; 14 15 //取消選中效果 16 [TableView deselectRowAtIndexPath:indexPath animated:YES]; 17 }

效果圖:

轉(zhuǎn)載于:https://www.cnblogs.com/0320y/p/5098670.html

總結(jié)

以上是生活随笔為你收集整理的ios基础篇(二十六)—— UITableViewCell的分组索引与标记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 午夜黄色一级片 | 亚洲精品热 | 日韩成人一区二区 | 国产a免费视频 | 日韩欧美在线观看一区二区三区 | 久久精品99北条麻妃 | 色二区 | 香蕉视频网页版 | cao在线| 国产免费观看视频 | 潘金莲三级80分钟 | 免费a网站 | 亚州中文字幕 | 九九久久视频 | 九九久久精品 | 草莓视频在线观看18 | 欧美性生活网站 | 伊人福利在线 | 综合狠狠开心 | 久久久久a | 午夜爱爱毛片xxxx视频免费看 | 涩涩在线播放 | 亚洲一级片 | 中文字幕第页 | 中文字幕有码在线视频 | 久久久久久人妻一区二区三区 | 黄色天堂av | 日韩黄色网络 | 亚洲人人人 | 国产一级一片 | 亚洲色网址 | 黄91在线观看 | 午夜性片 | 在线视频中文字幕 | 日日草日日干 | 91视频入口 | 波多野结衣欲乱上班族 | 欧美日韩国产精品一区 | 一区二区久久久 | www.黄色小说.com| 色老大视频 | 色免费视频 | 亚洲欧美成人一区二区三区 | 反差在线观看免费版全集完整版 | 日美毛片 | 成人国产精品一区二区 | 老地方在线观看免费动漫 | 亚洲性图一区二区 | 成人区人妻精品一区二区网站 | 超碰狠狠干 | 超碰人人在线 | 久啪视频| 色九九九| 久久久精品蜜桃 | 很黄很色的视频 | 怡红院一区二区 | √资源天堂中文在线视频 | 欧美888| 91极品视频| 伦理片中文字幕 | 男人添女人下部高潮视频 | 国产99re | 一级片美女 | 欧美日韩性 | 免费看污黄网站在线观看 | 国产喷白浆一区二区三区 | 琪琪射| 毛片免费一区二区三区 | 欧美不卡一二三 | 国产视频一区二区在线观看 | 貂蝉被到爽流白浆在线观看 | 免费处女在线破视频 | 精品人妻久久久久一区二区三区 | av手机天堂 | 麻豆视频精品 | 黑人巨大猛交丰满少妇 | 久久免费视频1 | 欧美色涩在线第一页 | 夜色一区二区三区 | 激情福利社 | 国产91清纯白嫩初高中在线观看 | 欧美大片免费高清观看 | 狠狠操一区二区 | 青青草97国产精品免费观看 | av免费成人| 欧美特一级片 | 神宫寺奈绪一区二区三区 | av影视网| 国产一区二区久久 | 在线视频这里只有精品 | 天天色天天色 | 亚洲av无码成人精品国产 | 欧美黑人精品一区二区 | 久操av| 黄色av国产| 99久久99久久 | 五月婷婷免费视频 | 在线成人毛片 | 国产三级一区二区三区 |