用tableView实现的一种加载数据的布局
用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实现的一种加载数据的布局的更多相关文章
- SrcollView分页加载数据(布局)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=& ...
- activity的四种加载模式
在android里,有4种activity的启动模式,分别为: standard, singleTop, singleTask和singleInstance, 其中standard和singleTop ...
- ios 图片的两种加载方式
控件加载图片,plist,懒加载,序列帧动画,添加动画效果. IOS中有2种加载图片的方式. 方式一:有缓存(图片所占用的内存会一直停留在程序中) + (UIImage *)imageNamed:(N ...
- Activity有四种加载模式(转)
Activity有四种加载模式: standard singleTop singleTask singleInstance 在多Activity开发中,有可能是自己应用之间的Activity跳转,或者 ...
- 活动 Activity 四种加载模式
singleTop要求如果创建intent的时候栈顶已经有要创建的Activity的实例,则将intent发送给该实例,而不发送给新的实例.(注意是栈顶,不在栈顶照样创建新实例!) singleTas ...
- Android Activity四种加载方式
Android之四种加载方式 (http://marshal.easymorse.com/archives/2950 图片) 在多Activity开发中,有可能是自己应用之间的Activity跳转,或 ...
- Entity Framework关联实体的三种加载方法
推荐文章 EF性能之关联加载 总结很好 一:介绍三种加载方式 Entity Framework作为一个优秀的ORM框架,它使得操作数据库就像操作内存中的数据一样,但是这种抽象是有性能代价的,故鱼和熊掌 ...
- Linux共享库两种加载方式简述
Linux共享库两种加载方式简述 动态库技术通常能减少程序的大小,节省空间,提高效率,具有很高的灵活性,对于升级软件版本也更加容易.与静态库不同,动态库里面的函数不是执行程序本身 的一部分,而是 ...
- 【Android进阶】Activity的四种加载模式
Activity的四种加载模式: 1.standard :系统的默认模式,一次跳转即会生成一个新的实例.假设有一个activity命名为Act1, 执行语句:startActivity(new Int ...
随机推荐
- docker仓库--使用tenxcloud
上传镜像 1. 在本地 docker 环境中输入以下命令进行登录 sudo docker login index.tenxcloud.com 2. 然后,对本地需要 push 的 image 进行标记 ...
- linux tar 命令
tar [-cxtzjvfpPN] 文件与目录 ....参数:-c :建立一个压缩文件的参数指令(create 的意思):-x :解开一个压缩文件的参数指令!-t :查看 tarfile 里面的文件! ...
- spark集群构建
一.spark启动有standalong.yarn.cluster,具体的他们之间的区别这里不在赘述,请参考官网.本文采用的是standalong模式进行搭建及将接使用. 1.首先去官网下载需要的sp ...
- .Net Core全球化多语言
参照:ASP.NET Core 全球化和本地化 步骤如下: 后台中的本地化. Startup.cs中注册服务并制定Resource文件的位置.注意:这里的位置不仅仅应用到Web层,如Infrastru ...
- button按钮被输入法顶起来,遮盖了input输入框
在做手机端的表单提交的时候,在chrome浏览器调试的时候,忘记输入法会引起布局的问题.在webApp里input输入框,会自动调起输入法,但是输入法会改变浏览器的可视区域的大小.就是会把浏览器可视区 ...
- 【转】Visio绘制WEB流程图的心得
一个哥们在MSN上告诉我,他们公司的交互设计师只产出流程图,并问我用什么标准评价流程图的好坏.他的说法把我彻底震了-这分工也太细了吧!也不知道该说他们那里这样是好还是不好. 不过仔细想来,我倒的确没有 ...
- java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES) 最蠢
我犯了七年前的错误,一个空格,昨天就想到的,还对比了一下密码有没有空格 问题原因1:多写空格 在datasource.properties 中的username 的值root后面多写了一个空格, jd ...
- 下拉框多选实现回显及sql
<td class="tabTd"><label>客户来源:</label></td> <td><select c ...
- Facebook回应追踪无账号用户:源于网站插件漏洞
近日,比利时隐私独立委员一项调查披露Facebook跟踪收集大量网站用户的上网足迹,同时触及那些没有注册Facebook账号的访客. 对此,Facebook公司回应这些恶劣跟踪行为在于社交媒体在安装插 ...
- [PHP] 重回基础(IO流)
IO流用来处理设备之间的数据传输 java对数据的操作是通过流的方式 java用于操作流的对象都在IO包中 流按操作数据分为两种:字节流与字符流 流按流向分为:输入流,输出流 字符流 抽象基类:Rea ...