A.实现思路
1.拖入UITableView
2.拖曳、连线UITableView控件
3.Controller遵守UITalbeViewDataSource协议
4.设置UITableView的dataSource
5.加载数据到Model
6.从Model解析数据,显示到View上
 
 
 
B.实现细节
1.UITableView style
(1)Grouped,成组出现,标题和尾部会被分隔开,如上图
 
(2)Plain
 
 
 

2. cars_simple.plist 文件结构

 
C.主要代码
Car.h
 1 //
2 // Car.h
3 // 01-CarBrand
4 //
5 // Created by hellovoidworld on 14/11/30.
6 // Copyright (c) 2014年 hellovoidworld. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10
11 @interface Car : NSObject
12
13 @property(nonatomic, strong) NSArray *cars;
14 @property(nonatomic, copy) NSString *title;
15 @property(nonatomic, copy) NSString *desc;
16
17 - (instancetype) initWithDictionary:(NSDictionary *) dictionary;
18 + (instancetype) carWithDictionary:(NSDictionary *) dictionary;
19 + (instancetype) car;
20
21 @end
 
Car.m
 1 //
2 // Car.m
3 // 01-CarBrand
4 //
5 // Created by hellovoidworld on 14/11/30.
6 // Copyright (c) 2014年 hellovoidworld. All rights reserved.
7 //
8
9 #import "Car.h"
10
11 @implementation Car
12
13 - (instancetype) initWithDictionary:(NSDictionary *) dictionary {
14 if (self == [super init]) {
15 self.cars = dictionary[@"cars"];
16 self.title = dictionary[@"title"];
17 self.desc = dictionary[@"desc"];
18 }
19
20 return self;
21 }
22
23 + (instancetype) carWithDictionary:(NSDictionary *) dictionary {
24 return [[self alloc] initWithDictionary:dictionary];
25 }
26
27 + (instancetype) car {
28 return [self carWithDictionary:nil];
29 }
30
31 @end
 
ViewController.m
 1 //
2 // ViewController.m
3 // 01-CarBrand
4 //
5 // Created by hellovoidworld on 14/11/30.
6 // Copyright (c) 2014年 hellovoidworld. All rights reserved.
7 //
8
9 #import "ViewController.h"
10 #import "Car.h"
11
12 @interface ViewController () <UITableViewDataSource>
13
14 @property (weak, nonatomic) IBOutlet UITableView *tableView;
15
16 @property(nonatomic, strong) NSArray *allBrandOfCars;
17
18 @end
19
20 @implementation ViewController
21
22 - (void)viewDidLoad {
23 [super viewDidLoad];
24 // Do any additional setup after loading the view, typically from a nib.
25
26 self.tableView.dataSource = self;
27 }
28
29 - (void)didReceiveMemoryWarning {
30 [super didReceiveMemoryWarning];
31 // Dispose of any resources that can be recreated.
32 }
33
34
35 #pragma mark - dataSource方法
36
37 /** Sections 数,组数 */
38 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
39 return self.allBrandOfCars.count; // 所有车的派系的数量
40 }
41
42 /** 组内的行数 */
43 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
44 Car *car = self.allBrandOfCars[section];
45 return car.cars.count; // 每个派系的车的牌子的数量
46 }
47
48 /** 组的标题
49 这里是车的派系
50 */
51 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
52 Car *car = self.allBrandOfCars[section];
53 return car.title;
54 }
55
56 /** 组的尾部 */
57 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
58 Car *car = self.allBrandOfCars[section];
59 return car.desc;
60 }
61
62 /** 行的内容 */
63 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
64 UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
65
66 Car *car = self.allBrandOfCars[indexPath.section]; // 车的派系
67 NSString *carName = car.cars[indexPath.row]; // 具体车的牌子
68
69 cell.textLabel.text = carName;
70
71 return cell;
72 }
73
74
75 /** 延迟加载plist文件中的数据 */
76 - (NSArray *) allBrandOfCars {
77 if (nil == _allBrandOfCars) {
78 NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cars_simple" ofType:@"plist"]];
79
80 NSMutableArray *mdictArray = [NSMutableArray array];
81 for (NSDictionary *dict in dictArray) {
82 Car *car = [Car carWithDictionary:dict];
83 [mdictArray addObject:car];
84 }
85
86 _allBrandOfCars = mdictArray;
87 }
88
89 return _allBrandOfCars;
90 }
91
92
93 @end
 

[iOS基础控件 - 6.1] 汽车品牌列表 UITableView多项显示的更多相关文章

  1. [iOS基础控件 - 6.4] 汽车品牌展示 Model嵌套/KVC/TableView索引

    A.需求 1.使用汽车品牌名称头字母为一个Model,汽车品牌为一个Model,头字母Model嵌套品牌Model 2.使用KVC进行Model封装赋值 3.展示头字母标题 4.展示索引(使用KVC代 ...

  2. [iOS基础控件 - 6.2] LOL英雄列表 UITableView单项显示

    A.需求 1.使用只有一个section的TableView来显示LOL 的英雄列表 2.内容包括标题.副标题.图标 3.使用plain样式 4.使用MVC模式     heros.plist 文件结 ...

  3. [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)

    A.概述      在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能      1.按钮点击后,显示为“已下载”,并且不 ...

  4. [iOS基础控件 - 6.7.1] 微博展示 代码

      Controller: // // ViewController.m // Weibo // // Created by hellovoidworld on 14/12/4. // Copyrig ...

  5. iOS 基础控件(下)

    上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...

  6. [iOS基础控件 - 7.0] UIWebView

    A.基本使用 1.概念 iOS内置的浏览器控件 Safari浏览器就是通过UIWebView实现的   2.用途:制作简易浏览器 (1)基本请求 创建请求 加载请求 (2)代理监听webView加载, ...

  7. [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储

    A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改)   这个代码 ...

  8. [iOS基础控件 - 6.10.2] PickerView 自定义row内容 国家选择Demo

    A.需求 1.自定义一个UIView和xib,包含国家名和国旗显示 2.学习row的重用   B.实现步骤 1.准备plist文件和国旗图片     2.创建模型 // // Flag.h // Co ...

  9. [iOS基础控件 - 6.9] 聊天界面Demo

    A.需求 做出一个类似于QQ.微信的聊天界面 1.每个cell包含发送时间.发送人(头像).发送信息 2.使用对方头像放在左边,我方头像在右边 3.对方信息使用白色背景对话框,我方信息使用蓝色背景对话 ...

随机推荐

  1. linux ps查看进程命令

    linux ps查看进程命令ps命令作用:将某个时间点的程序运作情况撷取下来 实例: [root@linux ~]# ps aux [root@linux ~]# ps -lA [root@linux ...

  2. 一周一话题之四(JavaScript、Dom、jQuery全面复习总结<Dom篇>)

    -->目录导航 一. 初探Dom 1. Dom介绍 二. Dom基础 1. window顶级对象 2. body.document对象事件 3. 通用的HTML元素的事件 4. 冒泡事件 5. ...

  3. C++不同进制整数

    在C++的整数常量中,整数分为十进制整数.八进制整数和十六进制整数. 那给出一个整型常量怎样区分是何种进制呢?/给出一个整型常量,如100,默认是十进制数,如果在该数前加0,如0100,则此数表示为八 ...

  4. Java中JSON的简单使用与前端解析

    http://www.blogjava.net/qileilove/archive/2014/06/13/414694.html 一.JSON JSON(JavaScript Object Notat ...

  5. while ((ch = getchar()) != EOF)中ch定义为char还是int型?cin、scanf等如何结束键盘输入

    2013-07-09 18:55:42 EOF是文件的结束符,具体可以作为文本文件的结束符,也可以作为键盘输入char类型数据时的结束符.对于不同的系统,EOF的定义可能不同,一般定义为-1.因为ch ...

  6. Vim常用命令手册

    这两年工作基本都是用vim,用习惯发现到哪都离不开这玩意. 退出编辑器 :w 将缓冲区写入文件,即保存修改:wq 保存修改并退出:x 保存修改并退出:q 退出,如果对缓冲区进行过修改,则会提示:q! ...

  7. IMX51+WINCE6.0平台缩写意义

    1.以EPIT为例 EPIT(Enhanced Periodic Interrupt Timer)为增强型周期中断定时器,其中有CR控制寄存器,要设置CR寄存器的SWR位,代码如下: // Asser ...

  8. 【HDOJ】4348 To the moon

    主席树区间更新,延迟标记. /* 4348 */ #include <iostream> #include <sstream> #include <string> ...

  9. 从Excel表格导入数据到数据库

    数据库:SQL 1.小数据直接粘贴 2.用导入向导 3.用SSIS包 4.用SQL语句 现在详细说一下第4种方法,以.xlsx文件为例 .xlsx文件需要用provider“Microsoft.ACE ...

  10. poj2352

    纪念树状数组初步(……): 这题已经给了y升序,y相同时x升序,(yeah) 所以容易想到O(n^2)的模拟算法: 其实分析一下就是对于当前xi,统计之前有多少个小于等于xi(因为已经保证了没有相同坐 ...