[iOS基础控件 - 6.6] 展示团购数据 自定义TableViewCell


// 设置尾部控件
self.tableView.tableFooterView = footerView;



- 新建xib描述view的结构
- 新建一个继承UIView的类(取决于xib根对象的class)
- 新建类名,和xib保持一致
@interface FooterRefreshView : UIView - 设置xib控件的class,连线
- 在自定义class中定义xib的加载类方法(屏蔽xib加载过程)
/** 初始化方法 */
+ (instancetype) footerRrefreshViewWithDelegate:(id<FooterRefreshViewDelegate>) delegate {
FooterRefreshView *footerRefreshView = [[[NSBundle mainBundle] loadNibNamed:@"FooterRefreshView" owner:nil options:nil] lastObject]; if (nil != delegate) {
footerRefreshView.delegate = delegate;
} return footerRefreshView;
} - class持有controller引用,发送消息给controller刷新数据
下面使用代理模式
- 自定义view的class持有controller的引用,耦合性强 —>使用代理
- 协议命名规范:控件类名+Delegate
- 代理方法普遍都是@optional
- 代理对象遵守代理协议,实现代理协议里面的方法
- 在需要的地方调用代理方法,给代理发送消息
FooterRefreshView.h
#import <UIKit/UIKit.h> @class FooterRefreshView; // 定义delegate协议
@protocol FooterRefreshViewDelegate <NSObject> @optional
- (void) footerRefreshViewClickedFooterRefreshButton:(FooterRefreshView *) footerRefreshView; @end @interface FooterRefreshView : UIView + (instancetype) footerRrefreshViewWithDelegate:(id<FooterRefreshViewDelegate>) delegate; @end
// xib控件的初始化调用方法
- (void)awakeFromNib {
self.loadingImage.hidden = YES;
}



/** 自定初始化的类方法,传入model数据 */
+ (instancetype) groupPurchaseCellWithGroupPurchase:(GroupPurchase *) groupPurchase;
/** 自定初始化的类方法,传入model数据 */
+ (instancetype) groupPurchaseCellWithGroupPurchase:(GroupPurchase *) groupPurchase {
GroupPurchaseCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupPurchaseCell" owner:nil options:nil] lastObject]; // 加载model中的数据,初始化界面
cell.groupPurchase = groupPurchase; return cell;
} /** 没有model数据的空cell */
+ (instancetype)groupPurchaseCell {
return [self groupPurchaseCellWithGroupPurchase:nil];
}
/** 加载Model数据,初始化界面 */
- (void) setGroupPurchase:(GroupPurchase *) groupPurchase {
if (nil != groupPurchase) {
self.titleLabel.text = groupPurchase.title;
self.iconImageView.image = [UIImage imageNamed:groupPurchase.icon];
self.priceLabel.text = [NSString stringWithFormat:@"¥%@", groupPurchase.price];
self.buyCountLabel.text = [NSString stringWithFormat:@"%@人已经购买", groupPurchase.buyCount];
} _groupPurchase = groupPurchase;
}


// 广告组
@property(nonatomic, strong) NSArray *ads;
/** 设置ads */
- (void) setAds:(NSArray *)ads {
if (nil != ads) {
CGFloat adImageWidth = AD_VIEW_WIDTH;
CGFloat adImageHeight = AD_VIEW_HEIGHT;
CGFloat adImageY = ; for (int i=; i<ads.count; i++) {
// 计算当前图片的水平坐标
CGFloat adImageX = i * adImageWidth; UIImageView *adImageView = [[UIImageView alloc] initWithFrame:CGRectMake(adImageX, adImageY, adImageWidth, adImageHeight)];
adImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", ads[i]]]; [self.scrollView addSubview:adImageView];
} // 设置滚动
self.scrollView.contentSize = CGSizeMake(ads.count * AD_VIEW_WIDTH, );
self.scrollView.scrollEnabled = YES;
} _ads = ads;
}
//设置头部广告
HeaderAdView *adView = [self genAdView]; // 手动拼装广告图片数据
self.tableView.tableHeaderView = adView;

[iOS基础控件 - 6.6] 展示团购数据 自定义TableViewCell的更多相关文章
- [iOS基础控件 - 6.11.5] 沙盒 & 数据存储
A.沙盒 每个APP都有一个沙盒,是独立存在的 1.Xcode5和Xcode6的模拟器文件目录 a.模拟器路径改版 (1)Xcode5中模拟器路径为:/Users/用户名/Library/Appl ...
- [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)
A.概述 在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能 1.按钮点击后,显示为“已下载”,并且不 ...
- [iOS基础控件 - 6.7] 微博展示 使用代码自定义TableCell(动态尺寸)
A.需求 1.类似于微博内容的展示 2.头像 3.名字 4.会员标志 5.内容 6.分割线 7.配图(可选,可有可无) code source: https://github.com/hellov ...
- [iOS基础控件 - 5.1] UIScrollView
A.需要掌握 UIScrollView 是一个能够滚动的视图控件,可以用来展示大量内容,如手机的“设置” 1.常见属性 2.常用代理方法 3.缩放 4.UIScrollView和UIPageContr ...
- [iOS基础控件 - 6.6.1] 展示团购数据代码
1.主控制器: // // ViewController.m // GroupPurchase // // Created by hellovoidworld on 14/12/3. // Cop ...
- [iOS基础控件 - 6.7.1] 微博展示 代码
Controller: // // ViewController.m // Weibo // // Created by hellovoidworld on 14/12/4. // Copyrig ...
- iOS 基础控件(下)
上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...
- [iOS基础控件 - 6.9] 聊天界面Demo
A.需求 做出一个类似于QQ.微信的聊天界面 1.每个cell包含发送时间.发送人(头像).发送信息 2.使用对方头像放在左边,我方头像在右边 3.对方信息使用白色背景对话框,我方信息使用蓝色背景对话 ...
- [iOS基础控件 - 7.0] UIWebView
A.基本使用 1.概念 iOS内置的浏览器控件 Safari浏览器就是通过UIWebView实现的 2.用途:制作简易浏览器 (1)基本请求 创建请求 加载请求 (2)代理监听webView加载, ...
随机推荐
- c缺陷与陷阱笔记-第四章 连接
1.变量的声明. 在不同的源文件中,应该是1个定义+多个声明的形式存在的,并且声明的类型和定义的类型要一样,否则可能会报错. 声明 : extern 类型 变量名 声明并定义: extern 类型 变 ...
- Fisher's exact test( 费希尔精确检验)
Fisher's exact test[1][2][3] is a statistical significance test used in the analysis ofcontingency t ...
- 使用PHP抓取网站ico图标
网站许久没用更新,以后会经常更新,本次分享一个使用PHP抓取网站ico的程序,提供一个网站列表后对网站的ico进行下载抓取,具体代码如下: <?php /** * 更新热站ico * gao 2 ...
- redolog 大小的实验
前言:近日因工作需要,测试postgresql和MySQL在oltp对比测试,因结果差异太多(MySQL测试结果比较差,相同环境),寻求大神帮助,有幸得叶大师和姜大师指点,指出my.cnf配置文件in ...
- Tiny4412之C语言实现流水灯,Tiny4412裸机程序[3]
在前边我们使用汇编完成了一个流水灯实验: Tiny4412汇编流水灯代码,Tiny4412裸机LED操作 ---- - -- -- -- - -- -- 修改: # ${MKBL2} ${SOURCE ...
- 【ZOJ】3609 Modular Inverse
1. 题目描述求乘法逆元. 2. 基本思路利用扩展gcd求逆元,模板题目. 3. 代码 /* 3609 */ #include <iostream> #include <sstrea ...
- [原]Unity3D深入浅出 - 认识开发环境中的Project面板
前面几个是用来创建脚步的,从Prefab说起: Prefab:预设物体,若一个Object在Scene中多处用到,即可选择为改对象创建一个Prefab.创建一个Prefab后,将源Object拖拽 ...
- BZOJ2055: 80人环游世界
题解: 总算A掉了,各种蛋疼... int main() { freopen("input.txt","r",stdin); freopen("out ...
- 银行爱“IOE”爱得有多深
本文由阿尔法工场欧阳长征推荐 导读:如果银行是一家海鲜酒楼,把IBM换掉相当于大搞一次装修,把Oracle换掉相当于把厨子和菜谱全部换掉,把EMC换掉相当于把放食材工具的储物间换个地方.难度在于,这海 ...
- MenuInflater用法
MenuInflater是用来加载menu布局文件的. 与LayoutInflater类似,应用程序运行时会预先加载资源中的布局文件,如果Menu布局中的资源比较多,会影响性能,所以可以选择MenuI ...