UITableView过度MVC思想(汽车列表展示项目)
2016-10-28 15:58
295 查看
那么今天还是跟同学举例汽车列表展示的项目,从最基本的tableView的用法到MVC思想的过度到深度封装和自定义cell以及cell的所有用法,那么废话不多说直接上代码,先看效果图
//
// ZZViewController.h
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ZZViewController :
UIViewController
@end
//
// ZZViewController.m
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import "ZZViewController.h"
#import "ZZCarGroup.h"
@interface
ZZViewController()
@property (weak,
nonatomic) IBOutlet
UITableView *tableView;
#pragma mark - 这里我们的数据是不是首先就要搞个数组来承载
/**
* 承载汽车模型
*/
@property (nonatomic,
strong) NSArray *carArr;
@end
@implementation ZZViewController
#pragma mark - 我们的数据通过懒加载的方式呈现出来我们不需要管他什么时候创建
- (NSArray *)carArr
{
if (_carArr ==
nil) {
// 初始化
// 德系品牌
ZZCarGroup *cg1 = [[ZZCarGroup
alloc] init];
cg1.title =
@"德系品牌";
cg1.desc =
@"德系品牌很好";
cg1.cars =
@[@"奥迪",
@"宝马",
@"奔驰",
@"奥迪",@"奥迪",
@"宝马",
@"奔驰",
@"奥迪",@"奥迪",
@"宝马",
@"奔驰",
@"奥迪"];
// 日韩品牌
ZZCarGroup *cg2 = [[ZZCarGroup
alloc] init];
cg2.title =
@"日韩品牌";
cg2.desc =
@"日韩品牌很好haohaohao";
cg2.cars =
@[@"本田",
@"丰田",
@"本田",
@"丰田",@"本田",
@"丰田",
@"本田",
@"丰田",@"本田",
@"丰田",
@"本田",
@"丰田",@"本田",
@"丰田",
@"本田",
@"丰田"];
// 欧系品牌
ZZCarGroup *cg3 = [[ZZCarGroup
alloc] init];
cg3.title =
@"欧系品牌";
cg3.desc =
@"欧系品牌goodgood";
cg3.cars =
@[@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利"];
_carArr =
@[cg1, cg2, cg3];
}
return
_carArr;
}
/**
* 隐藏状态栏
*/
- (BOOL)prefersStatusBarHidden
{
return
YES;
}
#pragma mark - 数据源方法
/**
* 一共有多少组数据
*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return
self.carArr.count;
}
/**
* 第section组有多少行
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// 取得第section组对应的模型
ZZCarGroup *cg =
self.carArr[section];
return cg.cars.count;
}
/**
* 每一行显示怎样的内容(cell)
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
UITableViewCell *cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
// 取出第indexPath.section组对应的模型
ZZCarGroup *cg =
self.carArr[indexPath.section];
// 取车第indexPath.row这行对应的品牌名称
NSString *car = cg.cars[indexPath.row];
// 设置cell显示的文字
cell.textLabel.text = car;
return cell;
}
/**
* 第section组显示怎样的头部标题
*/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ZZCarGroup *cg =
self.carArr[section];
return cg.title;
}
@end
//
// ZZCarGroup.h
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface ZZCarGroup :
NSObject
/**
* 头部标题
*/
@property (nonatomic,
copy) NSString *title;
/**
* 尾部标题(描述)
*/
@property (nonatomic,
copy) NSString *desc;
/**
* 这组的所有车(字符串)
*/
@property (nonatomic,
strong) NSArray *cars;
@end
//
// ZZCarGroup.m
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import "ZZCarGroup.h"
@implementation ZZCarGroup
@end
//
// ZZViewController.h
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ZZViewController :
UIViewController
@end
//
// ZZViewController.m
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import "ZZViewController.h"
#import "ZZCarGroup.h"
@interface
ZZViewController()
@property (weak,
nonatomic) IBOutlet
UITableView *tableView;
#pragma mark - 这里我们的数据是不是首先就要搞个数组来承载
/**
* 承载汽车模型
*/
@property (nonatomic,
strong) NSArray *carArr;
@end
@implementation ZZViewController
#pragma mark - 我们的数据通过懒加载的方式呈现出来我们不需要管他什么时候创建
- (NSArray *)carArr
{
if (_carArr ==
nil) {
// 初始化
// 德系品牌
ZZCarGroup *cg1 = [[ZZCarGroup
alloc] init];
cg1.title =
@"德系品牌";
cg1.desc =
@"德系品牌很好";
cg1.cars =
@[@"奥迪",
@"宝马",
@"奔驰",
@"奥迪",@"奥迪",
@"宝马",
@"奔驰",
@"奥迪",@"奥迪",
@"宝马",
@"奔驰",
@"奥迪"];
// 日韩品牌
ZZCarGroup *cg2 = [[ZZCarGroup
alloc] init];
cg2.title =
@"日韩品牌";
cg2.desc =
@"日韩品牌很好haohaohao";
cg2.cars =
@[@"本田",
@"丰田",
@"本田",
@"丰田",@"本田",
@"丰田",
@"本田",
@"丰田",@"本田",
@"丰田",
@"本田",
@"丰田",@"本田",
@"丰田",
@"本田",
@"丰田"];
// 欧系品牌
ZZCarGroup *cg3 = [[ZZCarGroup
alloc] init];
cg3.title =
@"欧系品牌";
cg3.desc =
@"欧系品牌goodgood";
cg3.cars =
@[@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利",@"兰博基尼",
@"法拉利"];
_carArr =
@[cg1, cg2, cg3];
}
return
_carArr;
}
/**
* 隐藏状态栏
*/
- (BOOL)prefersStatusBarHidden
{
return
YES;
}
#pragma mark - 数据源方法
/**
* 一共有多少组数据
*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return
self.carArr.count;
}
/**
* 第section组有多少行
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// 取得第section组对应的模型
ZZCarGroup *cg =
self.carArr[section];
return cg.cars.count;
}
/**
* 每一行显示怎样的内容(cell)
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
UITableViewCell *cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
// 取出第indexPath.section组对应的模型
ZZCarGroup *cg =
self.carArr[indexPath.section];
// 取车第indexPath.row这行对应的品牌名称
NSString *car = cg.cars[indexPath.row];
// 设置cell显示的文字
cell.textLabel.text = car;
return cell;
}
/**
* 第section组显示怎样的头部标题
*/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ZZCarGroup *cg =
self.carArr[section];
return cg.title;
}
@end
//
// ZZCarGroup.h
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface ZZCarGroup :
NSObject
/**
* 头部标题
*/
@property (nonatomic,
copy) NSString *title;
/**
* 尾部标题(描述)
*/
@property (nonatomic,
copy) NSString *desc;
/**
* 这组的所有车(字符串)
*/
@property (nonatomic,
strong) NSArray *cars;
@end
//
// ZZCarGroup.m
// 03-汽车品牌(MVC)
//
// Created by 周昭 on 16/10/28.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import "ZZCarGroup.h"
@implementation ZZCarGroup
@end
相关文章推荐
- 一、Unity3D 5.0.1-示例项目“汽车游戏”的展示及开发准备
- 【python项目实战】BBS论坛(5)帖子列表展示
- [Unity3d]虚拟3D汽车展示项目
- 封装项目整体架构,访问网络数据,展示列表数据,根据图片数量的不同来多条目加载,使用Universal-Image-Loader进行图片加载
- [thinkPHP5项目实战_25]前台文章列表展示
- 【无私分享:从入门到精通ASP.NET MVC】从0开始,一起搭框架、做项目(7.1) 模块管理,验证权限,展示模块列表
- 【Vue 入门】使用 Vue2 开发一个展示项目列表的应用
- RN实战阶段小结-小项目:书籍列表和展示
- 【Vue 入门】使用 Vue2 开发一个展示项目列表的应用
- IOS第七天(5:UiTableView 汽车品牌,复杂模型分组展示,A-Z索要列表) (2015-08-05 14:03)
- 项目及人员管理系统-修改员工信息列表展示
- 【Vue 入门】使用 Vue2 开发一个展示项目列表的应用
- [thinkPHP5项目实战_16]文章列表展示
- 1、项目搭建、本地视频列表展示
- 商城项目实战14:MyBatis分页插件(PageHelper)的使用以及商品列表展示
- [Unity3d]虚拟3D汽车展示项目
- 这个开源项目展示了如何实现一个横跨各种Android平台的音乐播放器,包括手机,平板,汽车,手表,电视等。Google官方推出,跨平台开发必看项目。
- 练习项目 一款新闻app的开发 (四):通过RecyclerView来展示新闻列表
- 【Vue 入门】使用 Vue2 开发一个展示项目列表的应用
- (转载)用多维动态博弈思想进行项目协调