uitableview加载MySQL数据_用tableView实现的一种加载数据的布局

//

//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"typedefenum: NSUInteger {

SECTION_ONE= 0,

SECTION_TWO,

MAX_SECTION,

} EViewController;@interface ViewController ()@property (nonatomic, strong) UITableView*tableView;

@property (nonatomic, strong) UIView*blockView;@end

@implementationViewController- (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:[UITableViewCellclass] forCellReuseIdentifier:CELL_FLAG];

[self.tableView registerClass:[ImageCellclass] 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 {returnMAX_SECTION;

}#pragma mark 重用cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {if (indexPath.section ==SECTION_ONE) {

ImageCell*cell =[tableView dequeueReusableCellWithIdentifier:IMAG_FLAG];returncell;

}else if (indexPath.section ==SECTION_TWO) {

UITableViewCell*cell =[tableView dequeueReusableCellWithIdentifier:CELL_FLAG];returncell;

}else{returnnil;

}

}#pragma mark 返回headerView

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {if (section ==SECTION_ONE) {returnnil;

}else if (section ==SECTION_TWO) {

UIView*view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];

view.backgroundColor=[UIColor redColor];returnview;

}else{returnnil;

}

}#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值