A.需求
1.使用只有一个section的TableView来显示LOL 的英雄列表
2.内容包括标题、副标题、图标
3.使用plain样式
4.使用MVC模式
 
 
heros.plist 文件结构:
 
 
这个其实很简单,直接上代码了
 //
// Hero.h
// LOLHero
//
// Created by hellovoidworld on 14/12/1.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h> @interface Hero : NSObject @property(nonatomic, copy) NSString *icon;
@property(nonatomic, copy) NSString *intro;
@property(nonatomic, copy) NSString *name; - (instancetype) initWithDictionary:(NSDictionary *) dictionary;
+ (instancetype) heroWithDictionary:(NSDictionary *) dictionary;
+ (instancetype) hero; @end
 
 //
// Hero.m
// LOLHero
//
// Created by hellovoidworld on 14/12/1.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import "Hero.h" @implementation Hero - (instancetype) initWithDictionary:(NSDictionary *) dictionary {
if (self = [super init]) {
self.icon = dictionary[@"icon"];
self.intro = dictionary[@"intro"];
self.name = dictionary[@"name"];
} return self;
} + (instancetype) heroWithDictionary:(NSDictionary *) dictionary {
return [[self alloc] initWithDictionary:dictionary];
} + (instancetype) hero {
return [self heroWithDictionary:nil];
} @end
 
 //
// ViewController.m
// LOLHero
//
// Created by hellovoidworld on 14/12/1.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import "ViewController.h"
#import "Hero.h" @interface ViewController () <UITableViewDataSource> // UITableView
@property (weak, nonatomic) IBOutlet UITableView *tableView; // 所有hero资料
@property(nonatomic, strong) NSArray *heros; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // 设置dataSource
self.tableView.dataSource = self; // 设置行高
self.tableView.rowHeight = ;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /** 隐藏状态栏 */
- (BOOL)prefersStatusBarHidden {
return YES;
} /** 延迟加载hero数据 */
- (NSArray *) heros {
if (nil == _heros) {
NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil]]; NSMutableArray *herosArray = [NSMutableArray array];
for (NSDictionary *dict in dictArray) {
Hero *hero = [Hero heroWithDictionary:dict];
[herosArray addObject:hero];
} _heros = herosArray;
} return _heros;
} #pragma mark - 列表方法 // section数, 默认是1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} // 特定section的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.heros.count;
} // 特定行的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Hero *hero = self.heros[indexPath.row]; // 必须使用"UITableViewCellStyleSubtitle"才能显示副标题
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; // 标题
cell.textLabel.text = hero.name; // 副标题
cell.detailTextLabel.text = hero.intro; // 图标
cell.imageView.image = [UIImage imageNamed:hero.icon]; return cell;
} @end

[iOS基础控件 - 6.2] LOL英雄列表 UITableView单项显示的更多相关文章

  1. [iOS基础控件 - 6.1] 汽车品牌列表 UITableView多项显示

    A.实现思路 1.拖入UITableView 2.拖曳.连线UITableView控件 3.Controller遵守UITalbeViewDataSource协议 4.设置UITableView的da ...

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

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

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

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

  4. iOS 基础控件(下)

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

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

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

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

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

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

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

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

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

  9. iOS基础 - 控件属性

    一.控件的属性 1.CGRect frame 1> 表示控件的位置和尺寸(以父控件的左上角为坐标原点(0, 0)) 2> 修改这个属性,可以调整控件的位置和尺寸 2.CGPoint cen ...

随机推荐

  1. php关于private、public成员变量访问问题

    如果类里面定义了__get($name)方法,则不论类的private成员还是public成员,都能够在类的外面通过类似$class->name访问到.如果是public变量,则不会自动调用ge ...

  2. PowerDesigner(五)-概念数据模型(CDM生成LDM,PDM和OOM)

    概念数据模型 概念数据模型(Conceptual Data Model,CDM):表达的是数据整体逻辑结构,该结构独立于任何软件和数据存储结构,即它只是系统分析人员,应用程序设计人员,维护人员和用户之 ...

  3. POJ 3252 Round Numbers(数位dp)

    题意:给定区间[l,r],l < r ,求区间中满足条件的正整数的个数:二进制表示下0的个数不少于1的个数. 分析:f(x)表示<=x时满足条件的数的个数,所求问题即为f(r)-f(l-1 ...

  4. 【mysql的编程专题⑥】视图

    视图是表的一个映射,是一张虚表,在结构上视图和普通的表没什么区别,一样可以用sql语句来增删改查; 视图创建后是一直存在数据库内 操作 创建视图 语法 CREATE [ALGORITHM]={UNDE ...

  5. PHP的执行原理/执行流程

    http://www.cnblogs.com/hongfei/archive/2012/06/12/2547119.html 更深入的学习和了解可以查看下面: 风雨的博客http://www.laru ...

  6. 【剑指offer】求逆序对的个数

    2013-09-07 10:50:31 面试题36:在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字构成一个逆序对.输入一个数组,求出这个数组中逆序对的总数. 小结: 最直观的的方法是: ...

  7. bzoj2906

    显然分块,由于颜色也有区间,我们的ans[l,r,k]表示块l和块r颜色1~k的权值和所以我们块的大小要设为n^(2/3),其它没什么说的,比较水 ..,..,..] of int64; g:..,. ...

  8. BZOJ_1031_[JSOI2007]_字符串加密_(后缀数组)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1031 长度为n的字符串形成环,枚举开头位置,得到n个长度为n的串,将这些串排序,然后按照顺序输 ...

  9. SQL Server使用规范(转)

    常见的字段类型选择 1.字符类型建议采用varchar/nvarchar数据类型 2.金额货币建议采用money数据类型 3.科学计数建议采用numeric数据类型 4.自增长标识建议采用bigint ...

  10. [zouxianghui] 清空GridPanel的checkbox选中行

    清空GridPanel的checkbox选中行,GridPanel.getSelectionModel().clearSelections();可以清空选中状态