日韩性视频-久久久蜜桃-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ò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 狼人伊人av| 欧美精品乱码视频一二专区 | av资源新版在线天堂 | 国产成人无码一二三区视频 | 国产麻豆精品一区二区 | www.狠狠| 国产黄色小视频在线观看 | 欧美黄色一级生活片 | 人妻少妇精品一区二区 | 亚洲一区无 | 五月天婷婷综合 | 干干干操操操 | 日韩不卡免费 | 好男人香蕉影院 | 婷婷在线综合 | 久久久无码一区二区三区 | 国产一区二区三区视频免费在线观看 | 国产美女诱惑 | 91黄色国产 | 黑人操欧美人 | 欧美精品一级片 | 欧美熟妇交换久久久久久分类 | 黄黄视频在线观看 | 99中文字幕在线观看 | 黄色在线免费 | 黄色免费网站在线 | 国产手机在线视频 | 久草超碰| 国产精品久久久爽爽爽麻豆色哟哟 | 中文字幕av久久 | 亚洲天堂av女优 | 国产不卡毛片 | 国产精品久久久久久无人区 | 色av色| 成年性生交大片免费看 | 女同性αv亚洲女同志 | 亚洲综合视频网站 | 国产精品丝袜视频无码一区69 | 午夜影院在线观看18 | 亚洲观看黄色网 | 奶波霸巨乳一二三区乳 | 特级西西人体444www | 黑人巨大精品欧美一区二区蜜桃 | 国产露脸91国语对白 | 在线午夜电影 | 国产一级视频 | 国产成人精品久久二区二区 | 一区二区三区视频免费 | 亚洲熟妇丰满大屁股熟妇 | 亚洲巨乳在线 | 国产精品视频在线看 | 国产在成人精品线拍偷自揄拍 | 性xxxx欧美老肥妇牲乱 | 亚洲免费看片 | 亚洲精品aa | 黄色短视频在线播放 | 免费看欧美一级片 | 99视频久 | 美国少妇在线观看免费 | 免费国产在线视频 | 亚洲午夜在线播放 | 日本泡妞xxxx免费视频软件 | 蜜乳av中文字幕 | 你操综合 | 日本免费黄色片 | 久久亚洲熟女cc98cm | 风流老熟女一区二区三区 | 成人福利视频在线观看 | 亚洲国产999 | 日本网站在线看 | 久久国产一二三 | 欧美一级片在线播放 | 欧美a图| 欧美男女激情 | 久久久视频在线 | 蜜臀视频网站 | 丁香色欲久久久久久综合网 | 婷婷五月综合激情 | 国产小视频免费观看 | 免费在线观看黄 | 亚洲射射 | 一区二区国产精品 | 欧美xxxxxxxxx| 蜜色视频 | 亚洲精品乱码久久久久久蜜桃欧美 | 中文字幕一区不卡 | 婷婷激情在线 | 国产99999| 成人看 | wwwxxxx在线观看| 波多野结衣视频在线观看 | 伊人超碰 | 美女被捅个不停 | 国产稀缺真实呦乱在线 | 国产精品电影一区 | www.成人| 成人图片小说 | 成人一二三 | 日本三级吃奶头添泬无码苍井空 |