当前位置: 首页 > news >正文

黑龙江生产建设兵团各连网站百度指数数据分析平台官网

黑龙江生产建设兵团各连网站,百度指数数据分析平台官网,wordpress 悬浮公告,武汉关键词排名系统iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序 一、plist文件和项目结构图 说明:这是一个嵌套模型的示例 二、代码示例: YYcarsgroup.h文件代码: 1 //2 // YYcarsgroup.h3 // 07-汽车展示(高级)4 //5 //…

iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序

一、plist文件和项目结构图

说明:这是一个嵌套模型的示例

二、代码示例:

 YYcarsgroup.h文件代码:

复制代码
 1 //2 //  YYcarsgroup.h3 //  07-汽车展示(高级)4 //5 //  Created by apple on 14-5-28.6 //  Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import <Foundation/Foundation.h>
10 
11 @interface YYcarsgroup : NSObject
12 @property(nonatomic,copy)NSString *title;
13 @property(nonatomic,strong)NSArray *cars;
14 
15 -(instancetype)initWithDict:(NSDictionary *)dict;
16 +(instancetype)carsgroupWithDict:(NSDictionary *)dict;
17 @end
复制代码

YYcarsgroup.m文件代码:

复制代码
 1 //2 //  YYcarsgroup.m3 //  07-汽车展示(高级)4 //5 //  Created by apple on 14-5-28.6 //  Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import "YYcarsgroup.h"
10 #import "YYcars.h"
11 
12 @implementation YYcarsgroup
13 -(instancetype)initWithDict:(NSDictionary *)dict
14 {
15     if (self=[super init]) {
16         //嵌套的字典转模型
17         self.title=dict[@"title"];
18         
19         //注意
20         NSArray *dictcars=dict[@"cars"];
21         //像下面这样写可以提高性能
22         NSMutableArray *arrayM=[NSMutableArray arrayWithCapacity:dictcars.count];
23         for (NSDictionary *dict  in dictcars) {
24             YYcars *yycars=[[YYcars alloc]initWithDict:dict];
25             [arrayM addObject:yycars];
26         }
27          // 赋值存储模型的数组给属性
28         self.cars=arrayM;
29     }
30     return self;
31 }
32 
33 +(instancetype)carsgroupWithDict:(NSDictionary *)dict
34 {
35     return [[self alloc]initWithDict:dict];
36 }
37 @end
复制代码

YYcars.h文件

复制代码
 1 //2 //  YYcars.h3 //  07-汽车展示(高级)4 //5 //  Created by apple on 14-5-28.6 //  Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import <Foundation/Foundation.h>
10 
11 @interface YYcars : NSObject
12 @property(nonatomic,copy)NSString *name;
13 @property(nonatomic,copy)NSString *icon;
14 
15 -(instancetype)initWithDict:(NSDictionary *)dict;
16 +(instancetype)carsWithDict:(NSDictionary *)dict;
17 @end
复制代码

 YYcars.m文件

复制代码
 1 //2 //  YYcars.m3 //  07-汽车展示(高级)4 //5 //  Created by apple on 14-5-28.6 //  Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import "YYcars.h"
10 
11 @implementation YYcars
12 
13 -(instancetype)initWithDict:(NSDictionary *)dict
14 {
15     if (self=[super init]) {
16         self.name=dict[@"name"];
17         self.icon=dict[@"icon"];
18     }
19     return self;
20 }
21 +(instancetype)carsWithDict:(NSDictionary *)dict
22 {
23     return [[self alloc]initWithDict:dict];
24 }
25 @end
复制代码

YYViewController.m文件

复制代码
  1 //2 //  YYViewController.m3 //  07-汽车展示(高级)4 //5 //  Created by apple on 14-5-28.6 //  Copyright (c) 2014年 itcase. All rights reserved.7 //8 9 #import "YYViewController.h"10 #import "YYcarsgroup.h"11 #import "YYcars.h"12 13 @interface YYViewController ()<UITableViewDataSource>14 @property (strong, nonatomic) IBOutlet UITableView *tableview;15 @property(nonatomic,strong) NSArray *car;16 @end17 18 @implementation YYViewController19 20 - (void)viewDidLoad21 {22     [super viewDidLoad];23     24     self.tableview.rowHeight=60.f;25     self.tableview.dataSource=self;26     NSLog(@"%d",self.car.count);27 }28 #pragma mark- 实现懒加载29 //1.从包中读取数据30 //2.字典转模型31 //3.返回cars32 -(NSArray *)car33 {34     if (_car==nil) {35       36         NSString *fullpath= [[NSBundle mainBundle]pathForResource:@"cars_total.plist" ofType:nil];37         NSArray  *arrayM=[NSArray arrayWithContentsOfFile:fullpath];38         39         NSMutableArray *carsarray=[NSMutableArray array];40         for (NSDictionary  *dict in arrayM) {41             YYcarsgroup *carsgroup=[YYcarsgroup carsgroupWithDict:dict];42             [carsarray addObject:carsgroup];43         }44         _car=[carsarray copy];45     }46     return _car;47 }48 49 50 #pragma mark-  实现tableview的数据展示51 //1.设置数据源,遵守协议52 //2.返回组53 //3.返回行54 //4.每组每行对应的数据55 //4.1去缓存中去取cell56 //4.2若没有,则创建cell,并盖章57 //4.3设置cell的数据58 //4.4返回cell59 60 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView61 {62     return self.car.count;63 }64 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section65 {66     YYcarsgroup *carsgroup=self.car[section];67     return carsgroup.cars.count;68 }69 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath70 {71     static NSString *identifier=@"car";72     //4.1去缓存中去取cell73     UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];74     //4.2若没有,则创建cell,并盖章75     if (cell==nil) {76         cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];77     }78     //4.3设置cell的数据79     //设置对应的组80     YYcarsgroup *carsgroup=self.car[indexPath.section];81     //设置对应的行82     YYcars *yycars=carsgroup.cars[indexPath.row];83 84     cell.imageView.image=[UIImage imageNamed:yycars.icon];85     cell.textLabel.text=yycars.name;86     //4.4返回cell87     return cell;88 }89 90 //设置每组的标题91 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section92 {93     YYcarsgroup *carsgroup=self.car[section];94     return carsgroup.title;95 }96 97 //设置索引98 -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView99 {
100     //利用kvc取出所有的标题
101     NSArray *title=[self.car  valueForKeyPath:@"title"];
102     return title;
103 }
104 
105 //隐藏状态栏
106 -(BOOL)prefersStatusBarHidden
107 {
108     return  YES;
109 }
110 @end
复制代码

实现效果:

三、注意点

1.设置索引

代码如下:

复制代码
//设置索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{//利用kvc取出所有的标题NSArray *title=[self.car  valueForKeyPath:@"title"];return title;
}
复制代码

2.cell的性能优化

代码如下:

复制代码
   static NSString *identifier=@"car";//4.1去缓存中去取cellUITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];//4.2若没有,则创建cell,并盖章if (cell==nil) {cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];}
复制代码

 

转载于:https://www.cnblogs.com/LiLihongqiang/p/5738976.html

http://www.lbrq.cn/news/2750833.html

相关文章:

  • 专门做mmd的网站个人网站设计方案
  • 大型外贸商城网站建设推广项目网站
  • 北京企业建设网站网站设计公司哪家专业
  • 高德地图是国产软件吗当阳seo外包
  • 腾讯公司做的购物网站搜索引擎营销的常见方式
  • 动漫设计与制作好就业吗seo推广方法
  • 厦门手机网站建设是什么网站收录查询爱站
  • 怎么查网站开发的语言宁德市房价
  • 动态网站开发在线测试百度广告费
  • 长沙网站建设维护少儿编程
  • 常州市做网站的公司品牌网络推广外包
  • xxx网站建设策划书范文广告优化师适合女生吗
  • 常德市做网站联系电话b2b网站排名
  • 做招聘网站创业如何宣传推广产品
  • 建设汽车行业网站云搜索引擎
  • 做网站需要用什么开发软件抖音搜索关键词推广
  • 专业柳州网站建设哪家好baike seotl
  • 做网站广告软件seo网站优化方案
  • 网站建设的行业新闻职业培训网络平台
  • 网站自建系统广东广州网点快速网站建设
  • 重庆綦江网站制作公司哪家专业大型网站制作
  • 网站批量发布互联网广告公司
  • 江阴做网站的公司搜索引擎收录提交入口
  • 陕西企业营销型网站广东网络seo推广公司
  • sem推广是什么意思呢常德seo招聘
  • 图片制作表情包的软件惠州百度seo在哪
  • 网站建设首选唯美谷在线识别图片来源
  • 完整网站开发视频鸡西seo顾问
  • 长沙网站建设长沙建设银行吉林网络推广公司
  • 网站权重怎么查询企业查询
  • Spark03-RDD02-常用的Action算子
  • C语言指针运算题
  • 衡石使用指南嵌入式场景实践之仪表盘嵌入
  • 数据结构初阶(16)排序算法——归并排序
  • Python-深度学习(一)
  • 【Canvas与玻璃光】铝圈蓝底玻璃光按钮