Xcode_7 iOS_9 索引栏 Objective-C (11)
来源:互联网 发布:ubuntu安装1080驱动 编辑:程序博客网 时间:2024/05/21 17:59
1、在上一节项目上作一点修改,去掉searchBar以及其协议,去掉原有数据源,重新添加新的数据源,team_dictionary.plist,目录结构和新数据源内容如下:
2、ViewController.h:
//// ViewController.h// TestProject//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#import <UIKit/UIKit.h>@interface ViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) NSDictionary *dicData;@property (nonatomic, strong) NSArray *listGroupname;@end
3、ViewController.m:
//// ViewController.m// TestProject//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#import "ViewController.h"#import "CustomCell.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib NSBundle *bundle = [NSBundle mainBundle]; NSString *plistPath = [bundle pathForResource:@"team_dictionary" ofType:@"plist"]; self.dicData = [[NSDictionary alloc] initWithContentsOfFile:plistPath]; NSArray *tempList = [self.dicData allKeys]; self.listGroupname = [tempList sortedArrayUsingSelector:@selector(compare:)];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSString *groupName = [self.listGroupname objectAtIndex:section]; NSArray *listTeam = [self.dicData objectForKey:groupName]; return [listTeam count];}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.listGroupname count];}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *groupName = [self.listGroupname objectAtIndex:section]; return groupName;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; NSString *groupName = [self.listGroupname objectAtIndex:section]; NSArray *listTeam = [self.dicData objectForKey:groupName]; cell.myLabel.text = [listTeam objectAtIndex:row]; return cell; }- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { NSMutableArray *listTitle = [[NSMutableArray alloc] initWithCapacity:[self.listGroupname count]]; for (NSString *item in self.listGroupname) { NSString *title = [item substringToIndex:1];//把A组后面的组字给去掉 [listTitle addObject:title]; } return listTitle;}@end
0 0
- Xcode_7 iOS_9 索引栏 Objective-C (11)
- Xcode_7 iOS_9 工具栏_导航栏 Objective-C (4)
- Xcode_7 iOS_9 Switch_SegmentControl_Slider 控件 Objective-C (2)
- Xcode_7 iOS_9 日期选择器 Objective-C (7)
- Xcode_7 iOS_9 普通选择器 Objective-C (8)
- Xcode_7 iOS_9 表视图 Objective-C (10)
- Xcode_7 iOS_9 静态表 Objective-C (12)
- Xcode_7 iOS_9 分页刷新 Objective-C (14)
- Xcode_7 iOS_9 textField和textView 关闭键盘 Objective-C (1)
- Xcode_7 iOS_9 获取设备型号 Objective-C (5)
- Xcode_7 iOS_9 屏幕滚动视图 Objective-C (6)
- Xcode_7 iOS_9 集合视图_CollectionViewController Objective-C (9)
- Xcode_7 iOS_9 修改单元格_移动单元格 Objective-C (13)
- Xcode_7 iOS_9 模态视图 Objective-C (15)
- Xcode_7 iOS_9 平铺导航_标签导航 Objective-C (16)
- Xcode_7 iOS_9 树形结构导航 Objective-C (17)
- Xcode_7 iOS_9 ActiveIndicatorView_ProgressView_警告窗_操作表 控件 Objective-C (3)
- Objective-C 程序 索引帖子
- 再谈STM32的CAN过滤器-bxCAN的过滤器的4种工作模式以及使用方法总结
- sublime Text 3实用功能和常用快捷键
- 第五章、epub文件处理 -- 解压epub文件
- 909422229__8、基数排序__程序员必须知道的8大排序和3大查找
- HIVE无法正常启动,报找不到jdbc的驱动类
- Xcode_7 iOS_9 索引栏 Objective-C (11)
- PullToRefresh的上拉加载下拉刷新
- ViewPager 实现 Galler 效果, 中间大图显示,两边小图展示
- 909422229__三种查找算法:顺序查找,二分法查找(折半查找),分块查找
- CentOS不能运行dialog的解决办法
- RadioGroip
- 第六章、epub文件处理 -- 解析container文件与.opf文件
- 手动添加Spring
- 同步函数与异步函数