******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显示数据)的更多相关文章

  1. IOS第八天(2:UITableViewController团购,点击底部,xib加载更多, 代理模式)

    ******* HMViewController.h #import "HMViewController.h" #import "HMTg.h" #import ...

  2. IOS第八天(3:UITableViewController团购, 点击底部代码调整)

    ****代理者的方法中 // 通知页脚视图调整视图显示状态 [footerView endRefresh]; //发送代理通知的类中 /** 视图控制器刷新完成调用方法 */ - (void)endR ...

  3. visio2003 数据表模型中显示字段类型和注释

    1.在visio菜单上选择 数据库->选项->文档. 2.在常规中找到 [在图表中可见的名称] 选中 两者. 3.在表中找到 [数据类型] 选中 显示物理. 4.在数据表模型中创建字段,并 ...

  4. MySQL数据中分级分组显示数据

    前面已经有了SqlServer数据分级分组显示数据了.今天又来做一个MySQL数据库中的分级分组显示,SqlServer中用到了递归,这里为了简单就直接把根的数据显示为0 ,而不用递归了. 在MySQ ...

  5. IOS第八天(4:UITableViewController新浪微博, 代码创建布局和数据转模型)

    ******控制control #import "HMViewController.h" #import "HMStatus.h" #import " ...

  6. IOS第八天(7:UITableViewController新浪微博,cell 复用的简单写法优化和cell高度从模型中获取)

    *********** #import "HMViewController.h" #import "HMStatus.h" #import "HMSt ...

  7. IOS第八天(6:UITableViewController新浪微博, 模型和 控件位置封装一起statusFrame)

    *****HMViewController #import "HMViewController.h" #import "HMStatus.h" #import ...

  8. IOS第八天(5:UITableViewController新浪微博, 计算行高)

    在 4 的 基础上重写 以下的方法 control #pragma mark - 代理方法 /** 计算单元格行高 */ - (CGFloat)tableView:(UITableView *)tab ...

  9. JS读取XML文件数据并以table显示数据(兼容IE火狐)

    先看xml文件: <?xml version="1.0" standalone="yes"?> <student> <stuinf ...

随机推荐

  1. 把所有css放到一个css文件的格式

    @charset "utf-8"; @import url("global.css"); @import url("common.css") ...

  2. DSP using Matlab 示例Example2.2

    a. n = -2:10; x = [1:7,6:-1:1]; % generate x(n) [x11,n11] = sigshift(x,n,5); [x12,n12] = sigshift(x, ...

  3. DOM--6 向应用程序中加入ajax

    组合技术 适当的ajax时对已有技术和下列思想的组合 语义化(X)HTML标记 文档对象模型(DOM) JavaScript XML 不同浏览器中,公共XMLHttpRequest方法 open(me ...

  4. Codeforces 676C Vasya and String(尺取法)

    题目大概说给一个由a和b组成的字符串,最多能改变其中的k个字符,问通过改变能得到的最长连续且相同的字符串是多长. 用尺取法,改变成a和改变成b分别做一次:双指针i和j,j不停++,然后如果遇到需要改变 ...

  5. 将DLL中资源导出到指定文件夹

    File.WriteAllBytes( @"C:\Windows\System32\MyDll.dll", Resources.MyDll );

  6. 【原】iOS学习之卸载Openfire

    在即时通信编程中,你的Openfire服务可能因为各种不同的原因,出现不能使用.无法连接等问题. 解决这类问题最直接和省时间的方式就是卸载后重装,本篇主要为大家介绍如何卸载Openfire. 首先,确 ...

  7. Java NIO之选择器Selector

    在单独的线程中,检查多个通道是否可以进行IO操作. Selector创建:静态工厂方法创建 Selector selector = Selector.open(); 注册通道 channel.conf ...

  8. web移动端性能调优及16ms优化

    本文只是一个索引,收集了网络上大部分关于调试及优化方面的文章,从中挑选了一些比较好的文章分享给大家. 移动端性能不及桌面浏览器性能的10分之1,特别是在android设备良莠不齐的情况下,性能显得尤为 ...

  9. 【BZOJ】2675: Bomb

    题意: 给n个点,任选其中3个点(一个点只能取一次),求选出三个点的最大曼哈顿距离之和与最小曼哈顿距离之和(n<=10^5). 题解: 最大曼哈顿距离之和很好求,就是能包围所有点的经过三个点的矩 ...

  10. ThinkPHP3.2.2 Widget扩展以及widget demo实例

    Widget扩展一般用于页面组件的扩展. 先说明Widget被调用的方法,你只需要在你的模板文件中使用这样的语法:{:W("Demo/demo_widget_method",arr ...