用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 ...
随机推荐
- Linux下安装了Xampp,但命令行使用不了MySQL
引用:http://www.2cto.com/database/201406/309521.html 刚安装好Xampp,使用localhost也能正常运行, phpMyAdimin也能正常登录 ...
- HTTP状态码列表
经常用的http状态码 1xx消息——请求已被服务器接收,继续处理2xx成功——请求已成功被服务器接收.理解.并接受3xx重定向——需要后续操作才能完成这一请求4xx请求错误——请求含有词法错误或者无 ...
- 剑指offer65:矩阵中的路径
题目描述: 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵 ...
- MapReduce几种提交方式
本地模式运行 1.在Windows里的IDE直接运行main方法,会将job提交给本地执行器localjobrunner执行 ---本地存放Hadoop安装包 ---输入输出数据可以放在本地路径下(c ...
- swiper在vue中的使用 及 神坑
一.实例化和导入 import Swiper from 'swiper'; let viewSwiper; let previewSwiper; 在外面声明全局变量,然后在初始化方法里面实例化swip ...
- 【转】JavaScript代码性能优化总结
本文作者:zifan 来自:携程设计委员会 链接:http://ued.ctrip.com/blog/javascript-code-performance-optimization-summary. ...
- C++ STL使用说明
标准模板库(Standard Template Library,STL)是一系列通用化组件的集合,包括容器(container).算法(algorithm)和迭代器(iterator). 迭代器ite ...
- UIKit 框架之Bar、Controller
UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarIt ...
- overfitting(过度拟合)的概念
来自:http://blog.csdn.net/fengzhe0411/article/details/7165549 最近几天在看模式识别方面的资料,多次遇到“overfitting”这个概念,最终 ...
- [转]SQL Server 2008- Get table constraints
本文转自:https://stackoverflow.com/questions/14229277/sql-server-2008-get-table-constraints You should u ...