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

歡迎訪問(wèn) 生活随笔!

生活随笔

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

编程问答

表视图中的侧索引

發(fā)布時(shí)間:2024/4/13 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 表视图中的侧索引 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? // Do any additional setup after loading the view, typically from a nib.

? ? //創(chuàng)建tableview

? ? UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

? ? tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);

? ? tableView.dataSource = self;

? ? tableView.delegate = self;

? ? [self.view addSubview:tableView];

? ? //設(shè)置索引字體的顏色

? ? tableView.sectionIndexColor = [UIColor greenColor];

? ? //設(shè)置索引背景顏色

? ? tableView.sectionIndexBackgroundColor = [UIColor redColor];

? ? //設(shè)置點(diǎn)擊后索引背景的顏色

? ? tableView.sectionIndexTrackingBackgroundColor = [UIColor blackColor];

? ? //獲取文件路徑

? ? NSString *filePath = [[NSBundle mainBundle] pathForResource:@"ListData" ofType:@"plist"];

? ? self.dataDic = [NSDictionary dictionaryWithContentsOfFile:filePath];

? ? allKeys = [self.dataDic allKeys];

?? ?

? ? //排序

? ? allKeys = [allKeys sortedArrayUsingSelector:@selector(compare:)];

}


- (void)didReceiveMemoryWarning {

? ? [super didReceiveMemoryWarning];

? ? // Dispose of any resources that can be recreated.

}


//返回組數(shù)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

? ? return allKeys.count;

}

//返回每組的行數(shù)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

? ? NSArray *cellArray =[self.dataDic objectForKey:allKeys[section]] ;

? ? return cellArray.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

? ? NSString *identifier = @"Cell";

? ? UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

? ? if (cell == nil) {

? ? ? ? cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

? ? }

? ? NSArray *cellArray =[self.dataDic objectForKey:allKeys[indexPath.section]] ;

? ? cell.textLabel.text = [cellArray objectAtIndex:indexPath.row];

? ? return cell;

}


//section標(biāo)題

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

? ? return allKeys[section];

}


//索引

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

? ? return allKeys;

}


- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

{

? ? return index;

}



轉(zhuǎn)載于:https://blog.51cto.com/10594302/1699719

超強(qiáng)干貨來(lái)襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生

總結(jié)

以上是生活随笔為你收集整理的表视图中的侧索引的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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