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. CAS SiteMinder (单点登录)

    http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/

  2. Asp.net调用百度搜索引擎

    ASP.NET 调用百度搜索引擎 百度搜索引擎提供了一段嵌入到页面中的代码 <form action="http://www.baidu.com/baidu" target= ...

  3. MySQL索引的查看创建和删除

    1.索引作用 在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万倍. 例如,有 ...

  4. java日历类Calendar简单使用

    import java.util.Calendar; import java.util.TimeZone; public class Test1 { public static void main(S ...

  5. unix network programming(3rd)Vol.1 [第2~5章]《读书笔记系列》

    13~22章 重要 第2章 传输层: TCP/ UDP / STCP (Stream Control Transmission Protocol) TCP 可靠,有重传机制,SYN队列号 UDP 不可 ...

  6. GIS:揭开你神秘的面纱

    转自:http://www.cnblogs.com/gisangela/archive/2013/02/20/2918884.html#!comments GIS从出现到为人所知,只不过经历了短短的几 ...

  7. mysql数据库基础的简单操作指南

    最近在学习mysql,本文是做的关于mysql学习的笔记,跟大家分享一下,希望对大家学习mysql知识有所助益.mysql现在几乎已经成了网站建设的主流数据库,很多php网站系统都采用了mysql数据 ...

  8. tomcat 5 启动过程官方文档

    http://tomcat.apache.org/tomcat-7.0-doc/architecture/startup/serverStartup.txt Licensed to the Apach ...

  9. [原]Android开发环境搭建

    [Date]2014-04-20 [Author]wintys (wintys@gmail.com) http://wintys.cnblogs.com [Keywords]android . 离线a ...

  10. Linux与Windows的8个不同

    (整理来自网络) 对刚刚接触Linux的人来说,很容易从windows的观念去理解Linux系统.今天扒一扒Win和Linux之间常见的8个区别. 一.Linux终端输入密码不回显字符 用户的密码在L ...