@property(nonatomic,strong) NSArray *car;
@end
复制代码
@implementation YYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableview.rowHeight=60.f;
self.tableview.dataSource=self;
NSLog(@"%d",self.car.count);
}
#pragma mark- 实现懒加载
//1.从包中读取数据
//2.字典转模型
//3.返回cars
-(NSArray *)car
{
if (_car==nil) {
NSString *fullpath= [[NSBundle mainBundle]pathForResource:@"cars_total.plist" ofType:nil];
NSArray *arrayM=[NSArray arrayWithContentsOfFile:fullpath];
NSMutableArray *carsarray=[NSMutableArray array];
for (NSDictionary *dict in arrayM) {
YYcarsgroup *carsgroup=[YYcarsgroup carsgroupWithDict:dict];
[carsarray addObject:carsgroup];
}
_car=[carsarray copy];
}
return _car;
}
#pragma mark- 实现tableview的数据展示
//1.设置数据源,遵守协议
//2.返回组
//3.返回行
//4.每组每行对应的数据
//4.1去缓存中去取cell
//4.2若没有,则创建cell,并盖章
//4.3设置cell的数据
//4.4返回cell
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.car.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
YYcarsgroup *carsgroup=self.car[section];
return carsgroup.cars.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier=@"car";
//4.1去缓存中去取cell
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
//4.2若没有,则创建cell,并盖章










