A.需求
1.头部广告
2.自定义cell:含有图片、名称、购买数量、价格
3.使用xib设计自定义cell,自定义cell继承自UITableViewCell
4.尾部“加载更多按钮”,以及其被点击之后的数据加载刷新、动画效果
 
code source: https://github.com/hellovoidworld/GroupPurchase
 
 
 
 
B.实现
1.使用MVC
M:团购Model
V:总View、cell的View(包含类和界面)
C:ViewController
 
2.分类管理代码文件
 
3.尾部footerView “加载更多"功能
     // 设置尾部控件
self.tableView.tableFooterView = footerView;
 
 
footerView设置的按钮自动宽度为tableView宽度,只能设置高度;x和y也不能设置。
要自定义按钮的的,使用xib进行自定义footerView嵌套
(1)使用button, 设计一个“加载更多”按钮
(2)加上等待图标
 
—>如何利用xib封装一个View:
  • 新建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
 
4.xib中创建的view初始化完毕之后不会调用class中的init方法,而是调用awakeFromNib方法
FooterRefreshView.h
 // xib控件的初始化调用方法
- (void)awakeFromNib {
self.loadingImage.hidden = YES;
}
 
 
5.分割线
其实就是高度为1的UIView
 
6.自定义cell
(1).自定义cell的子控件都要放到contentView里面
默认就是会放到contentView中
 
(2)创建继承自UITableViewCell的类
@interface GroupPurchaseCell : UITableViewCell
 
(3)创建xib文件描述cell的界面
 
(4)指定view的class,对控件进行连线
 
(5)在cell类中,定义一个model成员,用来存储这个cell的数据
 /** 自定初始化的类方法,传入model数据 */
+ (instancetype) groupPurchaseCellWithGroupPurchase:(GroupPurchase *) groupPurchase;
 
(6)创建初始化方法,使用model数据作为传入参数
 /** 自定初始化的类方法,传入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];
}
 
(7)传入model数据的同时,加载数据到view上面
 /** 加载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;
}
 
7.头部广告
其实就是之前的滚动广告放到 self.tableView.tableHeaderView
(1)设计界面
 
 
(2)创建class加载图片数据
 
(3)传入图片名的数组作为成员
 // 广告组
@property(nonatomic, strong) NSArray *ads;
 
(4)加载图片
 /** 设置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;
}
 
(5)在主controller,设置好图片数据,创建头部控件加到头部位置
     //设置头部广告
HeaderAdView *adView = [self genAdView]; // 手动拼装广告图片数据
self.tableView.tableHeaderView = adView;
 
(6)添加页码和自动轮播器
 
 
 

[iOS基础控件 - 6.6] 展示团购数据 自定义TableViewCell的更多相关文章

  1. [iOS基础控件 - 6.11.5] 沙盒 & 数据存储

    A.沙盒 每个APP都有一个沙盒,是独立存在的   1.Xcode5和Xcode6的模拟器文件目录 a.模拟器路径改版 (1)Xcode5中模拟器路径为:/Users/用户名/Library/Appl ...

  2. [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)

    A.概述      在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能      1.按钮点击后,显示为“已下载”,并且不 ...

  3. [iOS基础控件 - 6.7] 微博展示 使用代码自定义TableCell(动态尺寸)

    A.需求 1.类似于微博内容的展示 2.头像 3.名字 4.会员标志 5.内容 6.分割线 7.配图(可选,可有可无)   code source: https://github.com/hellov ...

  4. [iOS基础控件 - 5.1] UIScrollView

    A.需要掌握 UIScrollView 是一个能够滚动的视图控件,可以用来展示大量内容,如手机的“设置” 1.常见属性 2.常用代理方法 3.缩放 4.UIScrollView和UIPageContr ...

  5. [iOS基础控件 - 6.6.1] 展示团购数据代码

      1.主控制器: // // ViewController.m // GroupPurchase // // Created by hellovoidworld on 14/12/3. // Cop ...

  6. [iOS基础控件 - 6.7.1] 微博展示 代码

      Controller: // // ViewController.m // Weibo // // Created by hellovoidworld on 14/12/4. // Copyrig ...

  7. iOS 基础控件(下)

    上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...

  8. [iOS基础控件 - 6.9] 聊天界面Demo

    A.需求 做出一个类似于QQ.微信的聊天界面 1.每个cell包含发送时间.发送人(头像).发送信息 2.使用对方头像放在左边,我方头像在右边 3.对方信息使用白色背景对话框,我方信息使用蓝色背景对话 ...

  9. [iOS基础控件 - 7.0] UIWebView

    A.基本使用 1.概念 iOS内置的浏览器控件 Safari浏览器就是通过UIWebView实现的   2.用途:制作简易浏览器 (1)基本请求 创建请求 加载请求 (2)代理监听webView加载, ...

随机推荐

  1. linux pts/0的含义

    pts是所谓的伪终端或虚拟终端,具体表现就是你打开一个终端,这个终端就叫pts/0,如果你再打开一个终端,这个新的终端就叫pts /1.比如用who命令查询当前登录的用户,可以看到每个用户的TTY设备 ...

  2. hbase总结:如何监控region的性能

    转载:http://ju.outofmemory.cn/entry/50064 随着大数据表格应用的驱动,我们的HBase集群越来越大,然而由于机器.网络以及HBase内部的一些不确定性的bug,使得 ...

  3. linux grep和正则表达式

    虽然正则表达式经常都在用,但是很少能够静下心来仔细的总结一下.最近看了一个台湾人的网站叫做鸟哥Linux私房菜,关于正则表达式的描述挺详细的.在此,我进行一下总结,如果想仔细的学习正则表达式,请访问鸟 ...

  4. log4jdbc-remix安装配置

    1.maven安装依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w ...

  5. 通过web代理进行跨域访问,http请求返回超时的问题定位

    [现象] 在ajax通过web代理跨域访问时,http第一次登陆时正常,但是第二次再下发其他命令的时候总是返回 java.net.SocketTimeoutException: Read timed ...

  6. Hibernate逍遥游记-第1章-JDBC访问数据库

    1. package mypack; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.sw ...

  7. 去除右键菜单opendlg

    环境:windows8.1专业版 未知文件类型,右键会多出一个opendlg的选项!下面是移除的方法: 将下面的内容复制到记事本,并另存为XXX .reg,导入注册表即可!   Windows Reg ...

  8. kali2.0 系统自带截图功能

    (1)点击左下角的[显示应用程序] (2)在上面搜索栏输入关键字“screen” (3)进入截图选项页面

  9. Android 对话框用法

    来自:http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html Activities提供了一种方便管理的创建.保存.回复的对话框机制,例 ...

  10. UNIX内核的文件数据结构 -- v 节点与 i 节点

    龙泉居士:http://hi.baidu.com/zeyu203/item/cc89cfc0f36bfecc994aa07c 内核使用三种数据结构表示打开的文件(如图),他们之间的关系决定了在文件共享 ...