[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加载, ...
随机推荐
- CAS SiteMinder (单点登录)
http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
- Asp.net调用百度搜索引擎
ASP.NET 调用百度搜索引擎 百度搜索引擎提供了一段嵌入到页面中的代码 <form action="http://www.baidu.com/baidu" target= ...
- MySQL索引的查看创建和删除
1.索引作用 在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万倍. 例如,有 ...
- java日历类Calendar简单使用
import java.util.Calendar; import java.util.TimeZone; public class Test1 { public static void main(S ...
- unix network programming(3rd)Vol.1 [第2~5章]《读书笔记系列》
13~22章 重要 第2章 传输层: TCP/ UDP / STCP (Stream Control Transmission Protocol) TCP 可靠,有重传机制,SYN队列号 UDP 不可 ...
- GIS:揭开你神秘的面纱
转自:http://www.cnblogs.com/gisangela/archive/2013/02/20/2918884.html#!comments GIS从出现到为人所知,只不过经历了短短的几 ...
- mysql数据库基础的简单操作指南
最近在学习mysql,本文是做的关于mysql学习的笔记,跟大家分享一下,希望对大家学习mysql知识有所助益.mysql现在几乎已经成了网站建设的主流数据库,很多php网站系统都采用了mysql数据 ...
- tomcat 5 启动过程官方文档
http://tomcat.apache.org/tomcat-7.0-doc/architecture/startup/serverStartup.txt Licensed to the Apach ...
- [原]Android开发环境搭建
[Date]2014-04-20 [Author]wintys (wintys@gmail.com) http://wintys.cnblogs.com [Keywords]android . 离线a ...
- Linux与Windows的8个不同
(整理来自网络) 对刚刚接触Linux的人来说,很容易从windows的观念去理解Linux系统.今天扒一扒Win和Linux之间常见的8个区别. 一.Linux终端输入密码不回显字符 用户的密码在L ...