用tableView实现的一种加载数据的布局
2015-02-01 21:07
453 查看
用tableView实现的一种加载数据的布局
此博文是应朋友之邀解决他的业务逻辑问题
效果:
素材:
源码:
ImageCell.h 与 ImageCell.m
ViewController.m
此博文是应朋友之邀解决他的业务逻辑问题
效果:
素材:
源码:
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(0, -72, 320, 72 * 2)]; imageView.image = [UIImage imageNamed:@"1"]; [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 = 0, 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 += 72; rect.size.height -= 72; 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(0, 0, 320, 72)]; self.blockView.backgroundColor = [UIColor blackColor]; self.blockView.alpha = 0.f; [self.view addSubview:self.blockView]; } #pragma mark scrollView位移 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = scrollView.contentOffset.y; CGFloat percent = offsetY / 72.f; if (percent <= 0) { percent = 0; } else if (percent >= 1) { percent = 1; } self.blockView.alpha = percent; } #pragma mark 每个区row的个数 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == SECTION_ONE) { return 1; } else if (section == SECTION_TWO) { return 7; } else { return 0; } } #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(0, 0, 320, 40)]; 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 72; } else if (indexPath.section == SECTION_TWO) { return 200; } else { return 0; } } #pragma mark header高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == SECTION_ONE) { return 0.f; } else if (section == SECTION_TWO) { return 40; } else { return 0; } } @end
相关文章推荐
- iOS, PullTableView实现下拉刷新,上拉加载数据
- iOS TableView实现上拉加载更多数据
- 采用table+jQuery加载数据,实现数据与表格布局的分离
- 在ViewPager+Fragment实现Tabhost基础之上实现滑动到当前Fragment加载网络数据
- 上拉加载更多FJPullTableView文件的实现代码
- 使用sdWebImage实现对tableView的cell加载图片淡入淡出效果
- FJPullTableView 上拉加载更多的效果实现
- iphone利用线程实现数据的加载,并展示在table列表中
- iOS 开发-实现TableView的编辑功能以删除数据
- mono touch中TableView绑定数据和重新加载数据UIViewController
- 关于tableview 加载数据,性能优化
- 关于异步加载数据的又一种实现
- tableview实现cell有间隔,cell加载背景图片和选中图片
- IOS详解TableView——对话聊天布局的实现
- iPhone table 实现动态加载图片的教程-TableView中图片的延时加载
- iphone利用线程实现数据的加载,并展示在table列表中
- IOS之tableview 实现动态加载图片
- 关于异步加载数据的又一种实现
- Tableview和PickerView重新加载数据
- Android使用webview控件加载本地html,通过Js与后台Java实现数据的传递