网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

[IOS]UITableView分区+索引显示

效果:

成都创新互联10多年成都企业网站定制服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站定制及推广,对成都隧道混凝土搅拌车等多个方面拥有多年的网站推广经验的网站建设公司。

[IOS]UITableView分区+索引显示

步骤:

1.创建一个ViewController,New File->Cocoa Touch->Objective-C class->Class:ViewController,Subclass of:UIViewController

2.打开xib,在view中添加TableView,并将TableView的两个属性拖到File's Owner中,

可以设置tableview的分区样式,选择style

3.ViewController.h:

#import  @interface newViewController : UIViewController @property (retain, nonatomic) IBOutlet UITableView *tableView; @property(retain,nonatomic)NSDictionary *dic; @property(retain,nonatomic)NSArray *keys; @end
4.ViewController.m:

#import "newViewController.h"  @interface newViewController ()  @end  @implementation newViewController  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];     if (self) {         // Custom initialization     }     return self; }  - (void)viewDidLoad {     [super viewDidLoad];     NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];     self.dic = [NSDictionary dictionaryWithContentsOfFile:path];          self.keys = [self.dic allKeys];     self.keys = [self.keys sortedArrayUsingSelector:@selector(compare:)]; }  //tableView有多少分区 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {     return [self.keys count]; }  //每个分区对应多少行 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {     NSString *key = self.keys[section];//通过第几个分区拿到对应的key     NSArray *arr = [self.dic objectForKey:key];//通过这个key获得对应的Array     return [arr count]; }  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {     static NSString *str = @"str";     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];          if (cell == nil) {         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];     }     int section = [indexPath section];     int row = [indexPath row];          NSString *key = self.keys[section];     NSArray *arr = [self.dic objectForKey:key];     cell.textLabel.text = arr[row];     return cell; } //在每个分区上显示什么内容 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {     return self.keys[section]; }  - (void)didReceiveMemoryWarning {     [super didReceiveMemoryWarning];     // Dispose of any resources that can be recreated. } //设置索引 -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {     return self.keys; }  - (void)dealloc {     [_tableView release];     [self.keys release];     [self.dic release];     [super dealloc]; } @end



本文标题:[IOS]UITableView分区+索引显示
转载源于:http://bjjierui.cn/article/jesjgs.html

其他资讯