用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(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

时间: 2024-08-20 10:35:45

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

asp.net网站开发中用jquery实现滚动浏览器滚动条加载数据(类似于腾讯微博)_jquery

自从腾讯微博上线以来,基本上就开始用了,一直到现在,作为一个开发人员,也看到了腾讯微博一直在不停的改变,也不知道大家有没有发现,腾讯微博提供两种加载数据的方式,一种是分页,一种是滚动浏览器滚动条加载数据,分页功能我想大家都做得太多了,今天我与大家分享一下我用滚动条滚动加载数据下面开讲: 首先说一下思路,我用的是Jquery,然后通过Jquery的ajax()方法通过 HTTP 请求加载远程数据来实现的,用到Jquery,首先要应用jquery.min.js类库,如果本地没有,也可以直接引用下面地

Android之四种加载方式

  在多Activity开发中,有可能是自己应用之间的Activity跳转,或者夹带其他应用的可复用Activity.可能会希望跳转到原来某个Activity实例,而不是产生大量重复的Activity. 这需要为Activity配置特定的加载模式,而不是使用默认的加载模式. 加载模式分类及在哪里配置 Activity有四种加载模式: standard singleTop singleTask singleInstance 设置的位置在AndroidManifest.xml文件中activity元

jQuery常用的4种加载方式分析[原创]_jquery

本文实例分析了jQuery常用的4种加载方式.分享给大家供大家参考,具体如下: 1. 页面加载之前执行,与嵌入的js加载方式一样: (function($){})(jquery) 示例: (function($){ alert('Hello jb51'); })(jquery); 2. 页面加载后执行: $(document).ready(function(){}) 示例: $(document).ready(function(){ alert('Hello jb51'); }); 3. 页面加

Android实现listview动态加载数据分页的两种方法_Android

在android开发中,经常需要使用数据分页,比如要实现一个新闻列表的显示,或者博文列表的显示,不可能第一次加载就展示出全部,这就需要使用分页的方法来加载数据,在android中Handler经常用来在耗时的工作中,它接收子线程发送的数据,并使用数据配合更新UI,AsyncTask是在一个线程中执行耗时操作然后把结果传给UI线程,不需要你亲自去管理线程和句柄. 一.使用Handler+线程方法1.基础知识Handler在android系统中,主要负责发送和接收消息,它的用途主要有以下两种: (1

区分Activity的四种加载模式

在多Activity开发中,有可能是自己应用之间的Activity跳转,或者夹带其他应用的可复用Activity.可能会希望跳转到原来某个Activity实例,而不是产生大量重复的Activity. 这需要为Activity配置特定的加载模式,而不是使用默认的加载模式. 加载模式分类及在哪里配置 Activity有四种加载模式: standard singleTop singleTask singleInstance 设置的位置在AndroidManifest.xml文件中activity元素的

ios-UITableView从jsonURL加载数据

问题描述 UITableView从jsonURL加载数据 在UITableview的JSON的URL绑定数据,但是在执行过程中报错. NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8Str

SharePoint中如何实现ajax异步加载数据

初到公司,由原想的asp.net开发转向了SharePoint(简称SP)开发,个人感觉与之前差别不大,今天用sp实现异步加载数据的时候遇到点问题,之前在asp.net下一步都是用 jquery.ajax + .ashx 来实现,可是在sp下创建项的时候木有发现有ashx页面可以创建,那sp下如何实现异步加载数据那,有以下几种方式: 1.创建MyModule类实现IHttpModule借口并在主web.config下配置该节点,在里面添加事件处理,并添加类MyHandler实现IHttpHand

Android仿美团加载数据、小人奔跑进度动画对话框(附顺丰快递员奔跑效果)

我们都知道在Android中,常见的动画模式有两种:一种是帧动画(Frame Animation),一种是补间动画(Tween Animation).帧动画是提供了一种逐帧播放图片的动画方式,播放事先做好的图像,与gif图片原理类似,就像是在放电影一样.补间动画可以实现View组件的移动.放大.缩小以及渐变等效果.      今天我们主要来模仿一下美团中加载数据时小人奔跑动画的对话框效果,取个有趣的名字就是Running Man,奔跑吧,兄弟!话不多少,先上效果图,让各位大侠看看是不是你想要实现

Bootstrap Table从服务器加载数据进行显示的实现方法_javascript技巧

Bootstrap-Table是一个Boostrap的表格插件,能够将JSON数据直接显示在表格中.当然,这需要配置一些参数并进行初始化表格才行.其官方网站地址为:http://bootstrap-table.wenzhixin.net.cn/.里面可以下载使用所需的JS和CSS文件,以及参考文档和例子.         Bootstrap-Table显示数据到表格的方式有两种,一种是客户端(client)模式,一种是服务器(server)模式.         所谓客户端模式,指的是在服务器中