ios 汽车品牌展示案例

汽车组模型
// ZQRGroup.h
#import <Foundation/Foundation.h> @interface ZQRGroup : NSObject
/**
*组标题
*/
@property (nonatomic,copy) NSString *title;
/**
*品牌汽车
*/
@property (nonatomic,strong) NSArray *cars; - (instancetype)initWithDict:(NSDictionary *)dict;
+ (instancetype)groupWithDict:(NSDictionary *)dict;
@end //
// ZQRGroup.m
//
#import "ZQRGroup.h"
#import "ZQRCar.h" @implementation ZQRGroup - (instancetype)initWithDict:(NSDictionary *)dict
{
if(self=[super init]){
self.title=dict[@"title"];
NSArray *dictArray=dict[@"cars"];
NSMutableArray *carArray=[NSMutableArray array];
for (NSDictionary *dict in dictArray) {
ZQRCar *car=[[ZQRCar alloc] initWithDict:dict];
[carArray addObject:car];
}
self.cars=carArray;
}
return self;
}
+ (instancetype)groupWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
@end
汽车模型
//
// ZQRCar.h
//
#import <Foundation/Foundation.h>
@interface ZQRCar : NSObject
/**
*图标
*/
@property (nonatomic,copy) NSString *icon;
/**
*名称
*/
@property (nonatomic,copy) NSString *name; - (instancetype)initWithDict:(NSDictionary *)dict;
+ (instancetype)carWithDict:(NSDictionary *)dict;
@end //
// ZQRCar.m
//
#import "ZQRCar.h"
@implementation ZQRCar
- (instancetype)initWithDict:(NSDictionary *)dict
{
if(self=[super init]){
//self.icon=dict[@"icon"];
//self.name=dict[@"name"];
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+ (instancetype)carWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
@end
主控制器
//
// ZQRViewController.m
//
#import "ZQRViewController.h"
#import "ZQRGroup.h"
#import "ZQRCar.h" @interface ZQRViewController ()<UITableViewDataSource>
/**
* 车品牌组数据
*/
@property (nonatomic, strong) NSArray *groups;
@end @implementation ZQRViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (NSArray *)groups
{
if (_groups == nil) {
// 初始化
// 1.获得plist的全路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"cars_total.plist" ofType:nil]; // 2.加载数组
NSArray *dictArray = [NSArray arrayWithContentsOfFile:path]; // 3.将dictArray里面的所有字典转成模型对象,放到新的数组中
NSMutableArray *groupArray = [NSMutableArray array];
for (NSDictionary *dict in dictArray) {
// 3.1.创建模型对象
ZQRGroup *group = [ZQRGroup groupWithDict:dict]; // 3.2.添加模型对象到数组中
[groupArray addObject:group];
} // 4.赋值
_groups = groupArray;
}
return _groups;
} #pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.groups.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
ZQRGroup *group = self.groups[section]; return group.cars.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.定义一个循环标识
static NSString *ID = @"car"; // 2.从缓存池中取出可循环利用cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 3.缓存池中没有可循环利用的cell
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
} // 4.设置数据
ZQRGroup *group = self.groups[indexPath.section];
ZQRCar *car = group.cars[indexPath.row]; cell.imageView.image = [UIImage imageNamed:car.icon];
cell.textLabel.text = car.name; return cell;
} /**
* 第section组显示的头部标题
*/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ZQRGroup *group = self.groups[section];
return group.title;
} /**
* 返回右边索引条显示的字符串数据
*/
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [self.groups valueForKeyPath:@"title"];
} - (BOOL)prefersStatusBarHidden
{
return YES;
}
@end
ios 汽车品牌展示案例的更多相关文章
- [iOS基础控件 - 6.4] 汽车品牌展示 Model嵌套/KVC/TableView索引
A.需求 1.使用汽车品牌名称头字母为一个Model,汽车品牌为一个Model,头字母Model嵌套品牌Model 2.使用KVC进行Model封装赋值 3.展示头字母标题 4.展示索引(使用KVC代 ...
- (十八)TableView实践(多组汽车品牌展示)
对于多组数据,可能会用到模型的嵌套. 例如多组汽车,每组是一个模型,组内有多辆车的信息,每辆车的信息也是一个模型,相当于模型中有模型. 可以看到,每个item是一个字典,这要创建一个模型,而模型内部的 ...
- iOS开发——UI进阶篇(一)UITableView,索引条,汽车数据展示案例
一.什么是UITableView 在iOS中,要实现展示列表数据,最常用的做法就是使用UITableViewUITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳 UIT ...
- iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序
iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序 一.plist文件和项目结构图 说明:这是一个嵌套模型的示例 二.代码示例: YYcarsgroup.h文件代码: // // YYcar ...
- 【iOS开发-60】案例学习:多组数据的tableView设置、添加右側组索引、多层数据模型设置以及valueForKeyPath
效果: 这里的数据模型有两层:每一组汽车是一层模型,每一组里面的每一行汽车品牌也是一层模型. (1)我们先创建一个WSCars模型. 在WSCars.h中: #import <Foundatio ...
- 【iOS开发-56】案例BUG:button的enabled、控件的userInteractionEnabled以及两种提示框UIAlert和UIActionSheet
接上述案例找BUG:[iOS开发-51]案例学习:动画新写法.删除子视图.视图顺序.延迟方法.button多功能使用方法及icon图标和启动页设置 (1)BUG:答案满了就不能再点击optionbut ...
- 实时控制软件设计第一周作业-汽车ABS软件系统案例分析
汽车ABS软件系统案例分析 ABS 通过控制作用于车轮制动分泵上的制动管路压力,使汽车在紧急刹车时车轮不会抱死,这样就能使汽车在紧急制动时仍能保持较好的方向稳定性. ABS系统一般是在普通制动系统基础 ...
- 实战caffe多标签分类——汽车品牌与车辆外观(C++接口)[详细实现+数据集]
前言 很多地方我们都需要用到多标签分类,比如一张图片,上面有只蓝猫,另一张图片上面有一只黄狗,那么我们要识别的时候,就可以采用多标签分类这一思想了.任务一是识别出这个到底是猫还是狗?(类型)任务二是识 ...
- 【微信小程序】手写索引选择器(城市列表,汽车品牌选择列表)
摘要: 小程序索引选择器,点击跳转相应条目,索引可滑动,滑动也可跳转 场景:城市选择列表, 汽车品牌选择列表 所用组件: scroll-view(小程序原生) https://developers.w ...
随机推荐
- lanmp环境中php版本的升级为7.1
查看php版本的信息 vim ./lib/phps.sh 设置权限 chmod 755 ./lib/phps.sh 下载版本 ./lib/phps.sh 7.1.4 查看版本 php -v ...
- PHP引用赋值
<?php/** * 在PHP 中引用的意思是用不同的名字访问同一个变量内容 * 只有有名字的变量才可以引用赋值,否则会报错 * 引用赋值 不是在内存上同体,只是把各自的值关联起来 * unse ...
- Tree Requests CodeForces - 570D (dfs水题)
大意: 给定树, 每个节点有一个字母, 每次询问子树$x$内, 所有深度为$h$的结点是否能重排后构成回文. 直接暴力对每个高度建一棵线段树, 查询的时候相当于求子树内异或和, 复杂度$O((n+m) ...
- 如何查找php-fpm监听的端口
1. 找到php的安装位置.如: /usr/local/php-7.3.3 2. 进入安装目录下的etc/php-fpm.d目录,然后你会看到: 3. 打开www.conf,搜索listen关键字,你 ...
- 2018-2019 ACM-ICPC Brazil Subregional Programming Contest
A:留坑 B:二维sg函数,特判边界情况 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) / ...
- 四则运算web最终版
经过若干时间的奋战,终于完成了web版四则运算程序.团队成员:井小普.张贺. 设计思想: 在之前的程序基础上两人结合开发web系统. 首先,进行登录注册界面的编写,不同用户,对应不同的错题库,答题记录 ...
- CF-517C-思维/math
http://codeforces.com/contest/1072/problem/C 题目大意是给出两个数a,b ,找出若干个数p,使得 SUM{p}<=a ,找出若干个数q使得SUM{q} ...
- 绘图之EasyUI+Highcharts+Django
前言: 在web开发过程中经常会出现图表展示数据的业务需求,如何把数据通过图表的形式,展示在页面上呢?本文将结合EasyUI.Highcharts.Django做一个简单的图表展示web应用: 一.E ...
- EvalAI使用——类似kaggle的开源平台,不过没有kernel fork功能,比较蛋疼
官方的代码 https://github.com/Cloud-CV/EvalAI 我一直没法成功import yaml配置举办比赛(create a challenge on EvalAI 使用htt ...
- JavaScript创建对象(三)——原型模式
在JavaScript创建对象(二)——构造函数模式中提到,构造函数模式存在相同功能的函数定义多次的问题.本篇文章就来讨论一下该问题的解决方案——原型模式. 首先我们来看下什么是原型.我们在创建一个函 ...