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 ...
随机推荐
- vim使用02
编辑 剪切光标所在的字符: <x>; 剪切并插入: <s> 撤销操作:撤销至上一个命令之间的修改: <u> 恢复上一次撤销操作: <C r> 剪切光标所 ...
- Swift3.0语言教程使用字符串创建和初始化字符串
Swift3.0语言教程使用字符串创建和初始化字符串 Swift3.0语言教程使用字符串创建和初始化字符串,在编程语言中,字面值是很常见的数据描述形式.人们可以通过字面所表达的意思,获知其含义,尤其是 ...
- ReportNg 测试报告的定制修改【转】
前言 前段时间在Testerhome上面看到了测试报告生成系列之-------如何用 testNG 生成测试报告 简单的描述了一些测试报告的生成,接着有人在评论中回复说可以针对reportNg的测试报 ...
- virtual方法和abstract方法
在C#的学习中,容易混淆virtual方法和abstract方法的使用,现在来讨论一下二者的区别.二者都牵涉到在派生类中与override的配合使用. 一.Virtual方法(虚方法) virtual ...
- uva 107 - The Cat in the Hat
The Cat in the Hat Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty c ...
- Excel: Switch (transpose) columns and rows
链接:https://support.office.com/en-in/article/Switch-transpose-columns-and-rows-ed1215f5-59af-47e6-953 ...
- ccc 模拟重力
x=x+v v=v+gr cc.Class({ extends: cc.Component, properties: { velocity:{ default:null }, grivatity:{ ...
- (转)hbase master挂掉-zookeeper连接超时原因
link:http://www.51testing.com/?uid-445759-action-viewspace-itemid-812467 并行运行hbase删表,建表操作,多个表多个regio ...
- div+css定位position详解
div+css定位position详解 1.div+css中的定位position 最主要的两个属性:属性 absolute(绝对定位) relative(相对定位),有他们才造就了div+css布局 ...
- jsp 表单提交,服务器跳转方法 浏览器重定向 及 servlet映射时 路径问题
在jsp页面中,等提交表单数据时,最好用觉得路径. 写法如下: <form action ="<%=request.getContextPath()%>/do_login. ...