IOS第八天(1:UITableViewController团购,数据转模型,xib显示数据)
******HMTg.h 模型数据
#import <Foundation/Foundation.h> @interface HMTg : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *icon;
@property (nonatomic, copy) NSString *price;
@property (nonatomic, copy) NSString *buyCount; - (instancetype)initWithDict:(NSDictionary *)dict;
+ (instancetype)tgWithDict:(NSDictionary *)dict; + (NSArray *)tgs; @end
******HMTg.m 模型数据
#import "HMTg.h" @implementation HMTg - (instancetype)initWithDict:(NSDictionary *)dict
{
self = [super init];
if (self) {
[self setValuesForKeysWithDictionary:dict];
}
return self;
} + (instancetype)tgWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
} + (NSArray *)tgs
{
NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]]; NSMutableArray *arrayM = [NSMutableArray array];
for (NSDictionary *dict in array) {
[arrayM addObject:[self tgWithDict:dict]];
} return arrayM;
} @end
*********cell的文件HMTgCell.h
#import <UIKit/UIKit.h> @interface HMTgCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyCountLabel;
@end
****HMTgCell.m
#import "HMTgCell.h" @interface HMTgCell() @end @implementation HMTgCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
} - (void)awakeFromNib
{
// Initialization code
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end
**********HMViewController.m
#import "HMViewController.h"
#import "HMTg.h"
#import "HMTgCell.h" @interface HMViewController ()
@property (nonatomic, strong) NSArray *tgs;
@end @implementation HMViewController - (NSArray *)tgs
{
if (_tgs == nil) _tgs = [HMTg tgs];
return _tgs;
} - (void)viewDidLoad
{
[super viewDidLoad]; self.tableView.rowHeight = ; // 调整边距,可以让表格视图让开状态栏
self.tableView.contentInset = UIEdgeInsetsMake(, , , );
} ///** 隐藏状态栏 */
//- (BOOL)prefersStatusBarHidden
//{
// return YES;
//} #pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.tgs.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1. 可重用标示符
static NSString *ID = @"Cell";
// 2. tableView查询可重用Cell
HMTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 3. 如果没有可重用cell
if (cell == nil) {
// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
// 从XIB加载自定义视图
cell = [[[NSBundle mainBundle] loadNibNamed:@"HMTgCell" owner:nil options:nil] lastObject];
} // 4. 设置Cell内容
// 1> 取出模型
HMTg *tg = self.tgs[indexPath.row]; // cell.textLabel.text = tg.title;
// cell.imageView.image = [UIImage imageNamed:tg.icon];
//
// cell.detailTextLabel.text = [NSString stringWithFormat:@"¥%@ 已有%@人购买", tg.price, tg.buyCount];
cell.titleLabel.text = tg.title;
cell.iconView.image = [UIImage imageNamed:tg.icon];
cell.priceLabel.text = tg.price;
cell.buyCountLabel.text = tg.buyCount; return cell;
} @end
IOS第八天(1:UITableViewController团购,数据转模型,xib显示数据)的更多相关文章
- IOS第八天(2:UITableViewController团购,点击底部,xib加载更多, 代理模式)
******* HMViewController.h #import "HMViewController.h" #import "HMTg.h" #import ...
- IOS第八天(3:UITableViewController团购, 点击底部代码调整)
****代理者的方法中 // 通知页脚视图调整视图显示状态 [footerView endRefresh]; //发送代理通知的类中 /** 视图控制器刷新完成调用方法 */ - (void)endR ...
- visio2003 数据表模型中显示字段类型和注释
1.在visio菜单上选择 数据库->选项->文档. 2.在常规中找到 [在图表中可见的名称] 选中 两者. 3.在表中找到 [数据类型] 选中 显示物理. 4.在数据表模型中创建字段,并 ...
- MySQL数据中分级分组显示数据
前面已经有了SqlServer数据分级分组显示数据了.今天又来做一个MySQL数据库中的分级分组显示,SqlServer中用到了递归,这里为了简单就直接把根的数据显示为0 ,而不用递归了. 在MySQ ...
- IOS第八天(4:UITableViewController新浪微博, 代码创建布局和数据转模型)
******控制control #import "HMViewController.h" #import "HMStatus.h" #import " ...
- IOS第八天(7:UITableViewController新浪微博,cell 复用的简单写法优化和cell高度从模型中获取)
*********** #import "HMViewController.h" #import "HMStatus.h" #import "HMSt ...
- IOS第八天(6:UITableViewController新浪微博, 模型和 控件位置封装一起statusFrame)
*****HMViewController #import "HMViewController.h" #import "HMStatus.h" #import ...
- IOS第八天(5:UITableViewController新浪微博, 计算行高)
在 4 的 基础上重写 以下的方法 control #pragma mark - 代理方法 /** 计算单元格行高 */ - (CGFloat)tableView:(UITableView *)tab ...
- JS读取XML文件数据并以table显示数据(兼容IE火狐)
先看xml文件: <?xml version="1.0" standalone="yes"?> <student> <stuinf ...
随机推荐
- css3 -- 浏览器支持
浏览器支持的前缀: 1.浏览器兼容前缀 -webkit-transform:rotate(-3deg); /*为Chrome/Safari*/ -moz-transform:rotate(-3deg) ...
- angular.bind() 函数
angular.bind bind 函数有三个参数, 参一:是一个对象 参二:是一个 function 参三:是用来给参二传参数的,可写可不写,看你心情 参数也可以在调用函数的时候传,也可以当做第三个 ...
- 如何解决在Ue4编辑器中查看中文注释为乱码的情况
一般人都会在自己定义的函数后面添加注释,Ue4会在蓝图编辑器中显示这些注释,这是一个相当棒的设定. 但是如果这些注释是中文的话,在蓝图编辑器中就会显示乱码. 如何解决呢? 只需要把你的文件用UTF-8 ...
- git 学习笔记1--config & help
1. config 配置用户名和邮箱: git config --global user.name 'pzdn2009' git config --global user.email 10502441 ...
- Spring3.0 demo (注解自动注入)
这个demo是maven工程,目录结构如下 pom.xml maven依赖 .....省略 <dependency> <groupId>org.springframework& ...
- 简单验证码识别(matlab)
简单验证码识别(matlab) 验证码识别, matlab 昨天晚上一个朋友给我发了一些验证码的图片,希望能有一个自动识别的程序. 1474529971027.jpg 我看了看这些样本,发现都是很规则 ...
- BZOJ3569 : DZY Loves Chinese II
这回是真·强制在线了,首先这道题就是AHOI2013连通图的加强版,那道题k最大只有4 那道题的做法是: 取一个生成树,对每条非树边取一个随机权值, 对每条树边设为“覆盖它的所有非树边”的权值的xor ...
- (转)distcp从ftp到hdfs拷贝文件
link :http://blog.csdn.net/sptoor/article/details/11523469 distcp从ftp到hdfs拷贝文件: hadoop distcp ftp:// ...
- 20145308刘昊阳 《Java程序设计》实验三 敏捷开发与XP实践 实验报告
20145308刘昊阳 <Java程序设计>实验三 敏捷开发与XP实践 实验报告 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 统计的PSP(Personal ...
- xml学习
一,数据类型 xmlChar 对char的基本代替,是一个UTF-8编码字符串中的一个字节.如果你的数据使用了其他编码,在使用libxml函数前就必须转换为UTF-8. xmlDoc和xmlDocP ...