用tableView实现的一种加载数据的布局

此博文是应朋友之邀解决他的业务逻辑问题

效果:

素材:

源码:

ImageCell.h 与 ImageCell.m

//
// ImageCell.h
// TableView
//
// Created by YouXianMing on 15/2/1.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface ImageCell : UITableViewCell @end
//
// ImageCell.m
// TableView
//
// Created by YouXianMing on 15/2/1.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ImageCell.h" @implementation ImageCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, -, , * )];
imageView.image = [UIImage imageNamed:@""];
[self addSubview:imageView];
} return self;
} @end

ViewController.m

//
// ViewController.m
// TableView
//
// Created by YouXianMing on 15/2/1.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "ImageCell.h" #define CELL_FLAG @"Cell"
#define IMAG_FLAG @"Imag" typedef enum : NSUInteger {
SECTION_ONE = ,
SECTION_TWO, MAX_SECTION,
} EViewController; @interface ViewController ()<UITableViewDataSource, UITableViewDelegate> @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *blockView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; CGRect rect = self.view.bounds;
rect.origin.y += ;
rect.size.height -= ; self.tableView = [[UITableView alloc] initWithFrame:rect];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.layer.masksToBounds = NO;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CELL_FLAG];
[self.tableView registerClass:[ImageCell class] forCellReuseIdentifier:IMAG_FLAG];
[self.view addSubview:self.tableView]; self.blockView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
self.blockView.backgroundColor = [UIColor blackColor];
self.blockView.alpha = .f;
[self.view addSubview:self.blockView];
}
#pragma mark scrollView位移
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y; CGFloat percent = offsetY / .f;
if (percent <= ) {
percent = ;
} else if (percent >= ) {
percent = ;
} self.blockView.alpha = percent;
}
#pragma mark 每个区row的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == SECTION_ONE) {
return ;
} else if (section == SECTION_TWO) {
return ;
} else {
return ;
}
}
#pragma mark 几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return MAX_SECTION;
}
#pragma mark 重用cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == SECTION_ONE) {
ImageCell *cell = [tableView dequeueReusableCellWithIdentifier:IMAG_FLAG];
return cell;
} else if (indexPath.section == SECTION_TWO) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL_FLAG];
return cell;
} else {
return nil;
}
}
#pragma mark 返回headerView
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == SECTION_ONE) {
return nil;
} else if (section == SECTION_TWO) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
view.backgroundColor = [UIColor redColor];
return view;
} else {
return nil;
}
}
#pragma mark row高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == SECTION_ONE) {
return ;
} else if (indexPath.section == SECTION_TWO) {
return ;
} else {
return ;
}
}
#pragma mark header高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == SECTION_ONE) {
return .f;
} else if (section == SECTION_TWO) {
return ;
} else {
return ;
}
} @end

用tableView实现的一种加载数据的布局的更多相关文章

  1. SrcollView分页加载数据(布局)

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools=& ...

  2. activity的四种加载模式

    在android里,有4种activity的启动模式,分别为: standard, singleTop, singleTask和singleInstance, 其中standard和singleTop ...

  3. ios 图片的两种加载方式

    控件加载图片,plist,懒加载,序列帧动画,添加动画效果. IOS中有2种加载图片的方式. 方式一:有缓存(图片所占用的内存会一直停留在程序中) + (UIImage *)imageNamed:(N ...

  4. Activity有四种加载模式(转)

    Activity有四种加载模式: standard singleTop singleTask singleInstance 在多Activity开发中,有可能是自己应用之间的Activity跳转,或者 ...

  5. 活动 Activity 四种加载模式

    singleTop要求如果创建intent的时候栈顶已经有要创建的Activity的实例,则将intent发送给该实例,而不发送给新的实例.(注意是栈顶,不在栈顶照样创建新实例!) singleTas ...

  6. Android Activity四种加载方式

    Android之四种加载方式 (http://marshal.easymorse.com/archives/2950 图片) 在多Activity开发中,有可能是自己应用之间的Activity跳转,或 ...

  7. Entity Framework关联实体的三种加载方法

    推荐文章 EF性能之关联加载 总结很好 一:介绍三种加载方式 Entity Framework作为一个优秀的ORM框架,它使得操作数据库就像操作内存中的数据一样,但是这种抽象是有性能代价的,故鱼和熊掌 ...

  8. Linux共享库两种加载方式简述

      Linux共享库两种加载方式简述  动态库技术通常能减少程序的大小,节省空间,提高效率,具有很高的灵活性,对于升级软件版本也更加容易.与静态库不同,动态库里面的函数不是执行程序本身 的一部分,而是 ...

  9. 【Android进阶】Activity的四种加载模式

    Activity的四种加载模式: 1.standard :系统的默认模式,一次跳转即会生成一个新的实例.假设有一个activity命名为Act1, 执行语句:startActivity(new Int ...

随机推荐

  1. 解决Nginx 504 Gateway Time-out问题

    解决方案:在http里设置FastCGI相关参数,如: worker_processes 1; events { worker_connections 1024; } http { include m ...

  2. BiLSTM+CRF 实体识别

    https://www.cnblogs.com/Determined22/p/7238342.html 这篇博客 里面这个公式表示抽象的含义,表示的是最后的分数由他们影响,不是直观意义上的相加. 为什 ...

  3. redis 安装 与错误解决办法

    redis 安装与安装中遇到的错误 redis 安装 wget http://download.redis.io/releases/redis-4.0.11.tar.gz .tar.gz cd red ...

  4. spring整合elasticsearch之环境搭建

    推荐一个非常好的博客: 点我 // 测试使用docker下启动的es不管用, 在linux下或者windows下运行的es可用 // 进一步测试docker下启动的es链接时, 开启嗅探也链接不上, ...

  5. Android Studio 打包生成 APK

    1. 第一步 Build -> Generate Signed APK 2. 之后会要求开发者输入相关的密钥文件和密码 如果有则找到对应的 .jks 文件输入密码完成相应操作,否则则创建一个对应 ...

  6. Golang 并发Groutine实例解读(二)

    go提供了sync包和channel机制来解决协程间的同步与通信. 一.sync.WaitGroup sync包中的WaitGroup实现了一个类似任务队列的结构,你可以向队列中加入任务,任务完成后就 ...

  7. 【转】Visio绘制WEB流程图的心得

    一个哥们在MSN上告诉我,他们公司的交互设计师只产出流程图,并问我用什么标准评价流程图的好坏.他的说法把我彻底震了-这分工也太细了吧!也不知道该说他们那里这样是好还是不好. 不过仔细想来,我倒的确没有 ...

  8. activemq控制面板含义

    Name 消息队列的名称 Number Of Pending Messages 等待消费的消息数量,即未出队列的消息数量.可以理解为总接收数-总出队列数 (未持久化的话,重启acmq后会清零) Num ...

  9. C# 谁改了我的代码

    本文告诉大家一个特殊的做法,可以修改一个字符串常量 我们来写一个简单的程序,把一个常量字符串输出 private const string str = "lindexi"; sta ...

  10. Sql函数的三种写法

    以前复制的创建sql函数比较乱,现在将我自己项目中的三种sql函数做下对比,一目了然: (1)表值函数——方法一:直接创建临时表,并返回临时表.优点:函数体中间可以直接申明临时变量,并做各种逻辑处理, ...