35.小项目:汽车列表 版本3.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

更新说明:使用plist数据,隐藏电池状态栏等

------------- ViewController.m -------------

#import "ViewController.h"

#import "CZCarGroup.h"

#import "CZCar.h"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic,strong) NSArray *carGroups;

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

}

- (BOOL)prefersStatusBarHidden

{

return YES;

}

- (NSArray *)carGroups

{

if (_carGroups == nil)

{

NSString *path = [[NSBundle mainBundle] pathForResource:@"cars_total.plist" ofType:nil];

NSArray *groupDictArray = [NSArray arrayWithContentsOfFile:path];

NSMutableArray *tmpArray = [NSMutableArray array];

for (NSDictionary *groupDict in groupDictArray)

{

CZCarGroup *carGroup = [CZCarGroup carGroupWithDict:groupDict];

[tmpArray addObject:carGroup];

}

_carGroups = tmpArray;

}

return _carGroups;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return self.carGroups.count;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

CZCarGroup *carG = self.carGroups[section];

return carG.cars.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *ID = @"car";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

if(cell == nil)

{

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];

}

CZCarGroup *carGroup = self.carGroups[indexPath.section];

CZCar *car = carGroup.cars[indexPath.row];

cell.textLabel.text = car.name;

cell.imageView.image = [UIImage imageNamed:car.icon];

return cell;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

CZCarGroup *carGroup = self.carGroups[section];

return carGroup.title;

}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

return [self.carGroups valueForKeyPath:@"title"];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 60;

}

@end

------------- CZCarGroup.h -------------

#import <Foundation/Foundation.h>

@interface CZCarGroup : NSObject

@property (nonatomic,copy) NSString *title;

@property (nonatomic,strong) NSArray *cars;

- (instancetype)initWithDict:(NSDictionary *)dict;

+ (instancetype)carGroupWithDict:(NSDictionary *)dict;

@end

------------- CZCarGroup.m -------------

#import "CZCarGroup.h"

#import "CZCar.h"

@implementation CZCarGroup

- (instancetype)initWithDict:(NSDictionary *)dict

{

if (self = [super init])

{

self.title = dict[@"title"];

NSArray *dictArray = dict[@"cars"];

NSMutableArray *tmpArray = [NSMutableArray array];

for (NSDictionary *dict in dictArray)

{

CZCar *car = [CZCar carWithDict:dict];

[tmpArray addObject:car];

}

self.cars = tmpArray;

}

return self;

}

+ (instancetype)carGroupWithDict:(NSDictionary *)dict

{

return [[self alloc] initWithDict:dict];

}

@end

------------- CZCar.h -------------

#import <Foundation/Foundation.h>

@interface CZCar : NSObject

@property (nonatomic,copy) NSString *name;

@property (nonatomic,copy) NSString *icon;

- (instancetype)initWithDict:(NSDictionary *)dict;

+ (instancetype)carWithDict:(NSDictionary *)dict;

@end

------------- CZCar.m -------------

#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

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

时间: 2024-10-14 19:53:55

35.小项目:汽车列表 版本3.0的相关文章

33.小项目:汽车列表 版本1.0

------------- ViewController.m ------------- #import "ViewController.h" @interface ViewController () <UITableViewDataSource> @property (weak, nonatomic) IBOutlet UITableView *tableView; @end @implementation ViewController - (void)viewDidLo

34.小项目:汽车列表 版本2.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); 更新说明:增加多组数据展示 ------------- ViewController.m ------------- #import "ViewController.h" #import "CZCarGroup.h" @inter

32.小项目:喜马拉雅 版本3.0

更新说明:图片轮播器拖拽图片时暂停轮播. ------------- ViewController.m ------------- #import "ViewController.h" #define IMAGE_COUNT 5 @interface ViewController () <UIScrollViewDelegate> @property (weak, nonatomic) IBOutlet UIScrollView *scrView; @property (n

31.小项目:喜马拉雅 版本2.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); 更新说明:添加图片轮播器 --

30.小项目:喜马拉雅 版本1.0

------------- ViewController.m ------------- #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIScrollView *scrView; @property (nonatomic,strong) NSArray *arrs; @end @implementation ViewController - (N

37.小项目:英雄列表 版本2.0

------------- ViewController.m ------------- #import "ViewController.h" #import "CZHero.h" @interface ViewController () <UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate> @property (nonatomic,strong) NSArray *heros

36.小项目:英雄列表 版本1.0

------------- ViewController.m ------------- #import "ViewController.h" #import "CZHero.h" @interface ViewController () <UITableViewDataSource, UITableViewDelegate> @property (nonatomic,strong) NSArray *heros; @property (weak, no

react工程化项目搭建主流技术 umi3.0(或者&lt;3.0版本)+ dva + antd构建项目流程

umi+ dva + antd构建react工程项目(组件化开发搭建项目)1.官方网站安装node.js(并确保 node 版本是 10.13 或以上)2.先确保安装成功npm或者yarn3.npm i yarn tyarn -g (国内源)4.如果你没有 npx,需要先安装它,用于执行 node_modules 下的命令 yarn global add npx5.开始构建项目先区分版本: umi 3.0后也就是目前最新版本 mkdir myapp && cd myapp (新建建个项目目

web实践小项目&lt;一&gt;:简单日程管理系统(涉及html/css,javascript,python,sql,日期处理)

暑假自学了些html/css,javascript和python,苦于学完无处练手几乎过目即忘...最后在同学的建议下做了个简单日程管理系统.借第一版完成之际,希望能将实践期间犯过的错误和获得的新知进行整理,希望能给其他初学者提供参考,也希望有大神在浏览我粗糙的开发过程中能指出一些意见或建议. (阅读以下内容需要有一定的html/css,javascript,python和sql基础,and谢谢阅读!) 注:实践中的环境为ubuntu 14.04操作系统,python3.4(2.7实测也可行),