IOS开发基础之汽车品牌项目-14



//
//  ViewController.m
//  16-汽车品牌展示02
//
//  Created by 鲁军 on 2021/2/3.
//#import "ViewController.h"
#import "CZGroup.h"
#import "CZCar.h"
@interface ViewController () <UITableViewDataSource,UITableViewDelegate>@property(nonatomic,strong)NSArray *groups;@end@implementation ViewController- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{//
//    NSMutableArray *arrayIndex = [NSMutableArray array];
//    for(CZGroup *group in self.groups){//        [arrayIndex addObject:group.title];
//    }
//    return  arrayIndex;// return @[@"A",@"B",@"C",@"D"];return [self.groups valueForKey:@"title"];}#pragma 数据源方法- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{CZGroup *group = self.groups[section];return group.title;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{CZGroup *group  = self.groups[indexPath.section];CZCar *car = group.cars[indexPath.row];static NSString *ID = @"car_cell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if(cell==nil){cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];}cell.imageView.image = [UIImage imageNamed:car.icon];cell.textLabel.text=car.name;return  cell;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{CZGroup *group = self.groups[section];return  group.cars.count;
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return  self.groups.count;
}#pragma mark - 懒加载数据- (NSArray *)groups{if(_groups==nil){NSString *path = [[NSBundle mainBundle] pathForResource:@"cars_total.plist" ofType:nil];NSArray *arrayDict=[NSArray arrayWithContentsOfFile:path];NSMutableArray *arrayModels = [NSMutableArray array];for(NSDictionary *dict in arrayDict){CZGroup *model = [CZGroup groupWithDict:dict];[arrayModels addObject:model];}_groups = arrayModels;}return _groups;}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.}- (BOOL)prefersStatusBarHidden{return YES;
}@end
//
//  CZCar.h
//  16-汽车品牌展示02
//
//  Created by 鲁军 on 2021/2/3.
//#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN@interface CZCar : NSObject@property(nonatomic,copy)NSString *icon;
@property(nonatomic,copy)NSString *name;-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)carWithDict:(NSDictionary *)dict;@endNS_ASSUME_NONNULL_END
//
//  CZCar.m
//  16-汽车品牌展示02
//
//  Created by 鲁军 on 2021/2/3.
//#import "CZCar.h"@implementation CZCar
-(instancetype)initWithDict:(NSDictionary *)dict{if(self=[super init]){[self setValuesForKeysWithDictionary:dict];}return self;
}
+(instancetype)carWithDict:(NSDictionary *)dict{return [[self alloc] initWithDict:dict];
}
@end
//
//  CZGroup.h
//  16-汽车品牌展示02
//
//  Created by 鲁军 on 2021/2/3.
//#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN@interface CZGroup : NSObject
@property(nonatomic,copy)NSString *title;
@property(nonatomic,strong)NSArray *cars;-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)groupWithDict:(NSDictionary *)dict;@endNS_ASSUME_NONNULL_END
//
//  CZGroup.m
//  16-汽车品牌展示02
//
//  Created by 鲁军 on 2021/2/3.
//#import "CZGroup.h"
#import "CZCar.h"@implementation CZGroup
-(instancetype)initWithDict:(NSDictionary *)dict{if(self=[super init]){//        self.title = dict[@"title"];
//        self.cars=dict[@"cars"];[self setValuesForKeysWithDictionary:dict];//创建一个用来保存模型的数组NSMutableArray *arrayModels = [NSMutableArray array];//当有模型嵌套的时候需要注意的地方//手动的做一下字典转模型for(NSDictionary *item_dict in dict[@"cars"]){CZCar *model = [CZCar carWithDict:item_dict];[arrayModels addObject:model];}self.cars = arrayModels;}return  self;}
+(instancetype)groupWithDict:(NSDictionary *)dict{return [[self alloc] initWithDict:dict];}@end

IOS开发基础之汽车品牌项目-14相关推荐

  1. IOS开发基础之手势解锁项目案例

    IOS开发基础之手势解锁项目案例 项目最终实现效果. 由于缺少红色的error背景图.我自己从安卓项目找到一个手势解锁,然后通过ps添加粉红色的红圈,才得以解决.为了分享给大家源码,github和本地 ...

  2. IOS开发基础之模拟科技头条项目案例32

    IOS开发基础之模拟科技头条项目案例32 说说这个项目的技术要点核心 ,首先是异步网络请求,block的回调,sdWebImage的使用.各个控件的使用,NSDate日期的转换.自动适配屏幕工作,模型 ...

  3. IOS开发基础之微博项目

    IOS开发基础之微博项目 关键性代码 // // NJViewController.m // 06-预习-微博(通过代码自定义cell)// #import "NJViewControlle ...

  4. IOS开发基础之微博项目第1天-OC版

    IOS开发基础之微博项目第1天-OC版 纯代码创建的项目,具有参考价值 该资料来自2014年7月3号,虽然时间过去较长,但是oc和swift不同,oc语法迭代更新慢 具有一定的参考意义 涉及xib加载 ...

  5. IOS开发基础之UI的喜马拉雅的项目-10

    IOS开发基础之UI的喜马拉雅的项目-10 // // ViewController.m // 10-喜马拉雅 // // Created by 鲁军 on 2021/2/2. //#import & ...

  6. iOS开发基础知识--碎片44

    iOS开发基础知识--碎片44  iOS开发基础知识--碎片44 1:App跳转至系统Settings 跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置: NSURL *url = ...

  7. iOS开发基础-九宫格坐标(4)

    对iOS开发基础-九宫格坐标(3)的代码进行进一步优化. 新建一个 UIView 的子类,并命名为 WJQAppView ,将 appxib.xib 中的 UIView 对象与新建的视图类进行关联. ...

  8. IOS开发基础之OC的Block入门_Day09-Block

    IOS开发基础之OC的Block入门_Day09-Block block是oc的重要的基础知识,重点之重.跟协议一样重要,是进行函数回调重要手段.在后续的UI学习具有举足轻重的地位.学会基础的bloc ...

  9. IOS开发基础之音频工具类封装AVAudioPlayer

    IOS开发基础之音频工具类封装AVAudioPlayer 源码在我的主页下面 ,项目名称是AVAudioPlayer 关键性代码 工具类的封装 // // LJAudioTool.h // AVAud ...

最新文章

  1. ubuntu php xml模块,生成ubuntu自动切换壁纸xml文件的php代码
  2. 从陈坤微信号说起:微信公众平台开发者的江湖
  3. 更改日志级别_如何在运行时更改日志记录级别
  4. python绝对值函数偏码_绝对值python
  5. 【洛谷P1774】最接近神的人
  6. 程序员必备的21个Linux命令
  7. 数组占位符_Java基础 方法和数组
  8. Echarts单条折线可拖拽
  9. 电阻(1)电阻种类篇
  10. 饭店点餐系统之模块划分
  11. redis分布式锁实现(以抢红包为例)
  12. c语言情话编程,用c语言写的情话
  13. python做一个本地搜索工具_SecretFinder:一款基于Python脚本的JavaScript敏感信息搜索工具...
  14. MySql定期备份数据到历史表的解决方案
  15. 国庆节上映的电影有哪些?2014国庆节上映的动画电影盘点
  16. 铁流:中国突破半导体新工艺研发
  17. c#机器人聊天软件_C#winForm 聊天只能机器人(完整版)
  18. 微信隐藏功能系列:微信怎么深度清理内存?4个步骤让微信“瘦”下来
  19. 舆情监控系统python开源_TiDB 在西山居实时舆情监控系统中的应用
  20. 驱动程序(10) Windriver实现DMA传输时分配超大内存Buffer的办法

热门文章

  1. c语言control表题目,CMFCControl 问题
  2. 数学计算机培训反思,小学数学信息技术反思日志5
  3. C语言链表的转置算法,c语言编程集 数据结构 顺序表 点链表 数制转换 矩阵转置.doc...
  4. pythonturtle库使用心得_记录我的Python学习之旅(一)关于turtle库的基本用法
  5. 包和模块_月隐学python第13课
  6. mysql结构优化_MySQL优化----数据库结构优化
  7. java迭代器 异常_java-迭代器并发修改异常
  8. bch怎么挖_BCH是什么?
  9. python使用xml布局界面_Python:使用ElementTree更新XML文件,同时尽可能地保留布局...
  10. python处理netcdf_在python中高效读取netcdf变量