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 ...
随机推荐
- psql-02基本语法
客户端 数据库: 创建:createdb mydb; 删除: dropdb mydb; 连接: 连接: psql mydb; 断开连接: \q 查看当前版本: select version(); 直接 ...
- 制作一个访问量很高的大型网站,你会如何来管理所有HTML、CSS、JS与图片?
1.先确定全局样式和编码方式. 2.编写习惯,标注样式. 3.文件夹存放,命名.
- I Hate It(线段树基础)
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- SPOJ TSUM Triple Sums(FFT + 容斥)
题目 Source http://www.spoj.com/problems/TSUM/ Description You're given a sequence s of N distinct int ...
- ora-00031:session marked for kill处理oracle中杀不掉的锁
http://www.cnblogs.com/songdavid/articles/2223869.html 一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定 ...
- CF# 334 Lieges of Legendre
C. Lieges of Legendre time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CF#335 Intergalaxy Trips
Intergalaxy Trips time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Zookeeper 3.4.6 Client端流程粗略梳理
首先从Zookeeper入手,Zookeeper-->ClientCnxn-->sendThread/eventThread public ZooKeeper(String connect ...
- BZOJ4662 : Snow
首先离散化,即相邻关键点之间的部分可以压成一段. 注意到区间互不包含,因此排序后每个位置的清理影响到的是一段连续区间的清理工的工作长度. 这显然可以用线段树维护,支持区间减去一个数,单点加上$inf$ ...
- 假装有题目 & Trie+贪心
题意: 从N个数中选出两个使其异或值最大. SOL: 建立一个01字典树,然后对每一个数在树上贪心即可...Trie一个挺好的运用,复杂度O(n*n的位数) CODE: #include <cs ...