[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加载, ...
随机推荐
- ajax跨域访问的解决方案
今天的工作中要访问摄像机内部的一个web站点,这就涉及到jquery的ajax跨域访问的问题.我使用的是jquery1.7的版本,下面总结如下: 问题一:一开始用IE调试,总是返回No Transpo ...
- C#操作xml文档,cuid,dategridview显示数据
界面 //所有的数据全部在集合中 //dgv控件绑定List集合,List集合中有User类的对象,对象里有属性,把属性绑定到没列的数据上 dgv.Da ...
- ArcGIS学习记录—KMZ KML与SHP文件互相转换
1.在google earth中绘制边界 工具栏中选择"Add Polygon".随意绘制一个多边形. 右击添加的图层名(左侧)保存位置为,选择保存为kmz或kml文件. ...
- Django用户认证系统(三)组与权限
Django的权限系统很简单,它可以赋予users或groups中的users以权限. Django admin后台就使用了该权限系统,不过也可以用到你自己的代码中. User对象具有两个ManyTo ...
- JS动画 | 用TweenMax实现收集水滴效果
之前在CodePen上接触了TweenMax, 被它能做到的酷炫效果震撼了. (文末放了5个GSAP的效果GIF) 最近要做一个"收集水滴"的动效, 于是就试用了一下TweenMa ...
- Linux内核OOM机制的详细分析
Linux 内核有个机制叫OOM killer(Out-Of-Memory killer),该机制会监控那些占用内存过大,尤其是瞬间很快消耗大量内存的进程,为了防止内存耗尽而内核会把该进程杀掉.典型的 ...
- System.Drawing.Graphics中比较重要的几个方法
方法 常见参数 绘制的图形 DrawLine 钢笔.起点和终点 一段直线 DrawRectangle 钢笔.位置和大小 空心矩形 DrawEllipse 钢笔.位置和大小 空心椭圆 FillRecta ...
- IT国家重点实验室
软件工程国家重点实验室(武汉大学): http://www.sklse.whu.edu.cn/ 南京大学: http://keysoftlab.nju.edu.cn/ 水声技术国家重点实验室 http ...
- 最短路径(Floyd 模板题)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2143&cid=1186 #include<stdio.h> #incl ...
- bzoj1079: [SCOI2008]着色方案
ci<=5直接想到的就是5维dp了...dp方程YY起来很好玩...写成记忆化搜索比较容易 #include<cstdio> #include<cstring> #inc ...