资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

[IOS]UITableView分区+索引显示-创新互联

效果:

创新互联公司是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,微信小程序,十载建站对火锅店设计等多个行业,拥有丰富的网站制作经验。

[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


另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:[IOS]UITableView分区+索引显示-创新互联
文章起源:http://cdkjz.cn/article/ejppd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220