//2、实现数据源协议
@interface SettingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) SettingView *settingView;
@property(nonatomic,strong) NSArray *biggerArrays;
@end
@implementation SettingViewController
-(void)loadView
{
self.settingView = [[SettingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.settingView;
}
- (void)viewDidLoad {
[super viewDidLoad];
//1、设置数据源
self.settingView.tableView.dataSource = self;
self.settingView.tableView.delegate = self;
//初始化数据
self.biggerArrays = @[
@[@"通用", @"隐私"],
@[@"iCloud", @"地图", @"Safari",
@"照片与相机", @"Game Center"],
@[@"Twitter", @"FaceBook", @"Flickr",
@"Vimeo", @"新浪微博", @"腾讯微博"],
@[@"开发者"]
];
}
#pragma mark 实现协议方法
#pragma mark 设置分组数,可选方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//返回数字,代表几个分组
return _biggerArrays.count;
}
#pragma mark 设置行数 ,必须实现的方法
//有多少个分区,这个方法就走多少次。===当前屏幕能显示的行数,当你的cell将要显示的时候都会执行此方法。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//返回数字,代表行数。
NSArray *smallArray = _biggerArrays[section];
return smallArray.count;
}
#pragma mark 设置每行上显示什么内容,必须实现的方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#pragma mark 重用机制
//0.创建标识符
static NSString *cellID = @"tttt";
//1.从重用队列中获取cell
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellID];
//2.判断是否存在,如果不存在,则创建
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
//3.使用
cell.textLabel.text = _biggerArrays[indexPath.section][indexPath.row];
return cell;
}
#pragma mark 设置分区标题
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"投标太";
}
#pragma mark 设置快速索引
-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return @[@"1",@"2",@"3"];
}
#pragma mark 设置cell的高度
//设置不同行的不同高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 50;
}
return 44;
}
#pragma mark 选中了哪一个cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",indexPath);
}