用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 ...
随机推荐
- centos7的防火墙配置
centos7 不在使用iptables作为防火墙, 而是使用firewalld规则, 好吃是支持动态更新, 不需要重启服务, 第二个就是加入了zone概念. 所以和centos6在防火墙配置上有很大 ...
- java将list转为树形结构的方法
目录 1.通过转化成json封装数据 2.通过java8 stream转换 1.通过转化成json封装数据 原始数据如下 [ { "name":"甘肃省", & ...
- DES对 json 、http参数加密解密算法
网上众多大神们的众多方式实现加解密操作及保障数据安全性.今天无意中发现一篇以 DES加密解密算法.摘抄如下 工具类: import java.security.SecureRandom; import ...
- Python魔法方法之属性访问 ( __getattr__, __getattribute__, __setattr__, __delattr__ )
通常情况下,我们在访问类或者实例对象的时候,会牵扯到一些属性访问的魔法方法,主要包括: ① __getattr__(self, name): 访问不存在的属性时调用 ② __getattribute_ ...
- Java Date SimpleDateFormat
public static void main(String[] args) { long millis = 1492741275301L; Calendar calendar = Calendar. ...
- sql中同一个表一个字段的值赋值给另一个字段
UPDATE SG_User SET DefaultOrganizationID = OrganizationID
- .net Core学习笔记之MemoryCache
.NET Core支持多种不同的缓存,其中包括MemoryCache,它表示存储在Web服务器内存中的缓存: 内存中的缓存存储任何对象; 分布式缓存界面仅限于byte[] 1:在.net co ...
- .net面试题[转载]
1.简述private.protected.public.internal修饰符的访问权限. private:私有成员,在类的内部才可以访问. protected:保护成员,该类内部和继承类中可以访问 ...
- JS数组sort比较函数
转载:http://www.cnblogs.com/ljchow/archive/2010/06/30/1768683.html 我们知道,数组的sort方法可以对数组元素进行排序,默认是按ASCII ...
- Java基础教程(14)--嵌套类
Java允许在一个类中定义另外一个类,这样的类被称为嵌套类,就像下面这样: class OuterClass { ... class NestedClass { ... } } 嵌套类分为两种 ...