#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableView;
@property(nonatomic,strong) NSMutableArray * dataSource;
@property(nonatomic,strong) NSMutableArray * groupNameArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//获取plist 文件
NSURL * url = [[NSBundle mainBundle]URLForResource:@"Property List" withExtension:@"plist"];
NSDictionary * dic = [NSDictionary dictionaryWithContentsOfURL:url];
_dataSource = [NSMutableArray new];
_groupNameArray = [NSMutableArray new];
for (NSString * key in dic) {
[_groupNameArray addObject:key];
[_dataSource addObject:dic[key]];
}
[self.view addSubview:self.tableView];
}
-(UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _groupNameArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_dataSource[section] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
cell.textLabel.text = _dataSource[indexPath.section][indexPath.row];
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return _groupNameArray[section];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
ios 分区套对应表格
最新推荐文章于 2019-09-09 22:23:57 发布