TAG

RSS订阅

收藏本站

设为首页

当前位置:主页 > 移动开发 > IOS开发 >

uitableview处理section的不悬浮,禁止section停留的方法

发布时间:2015-01-05 17:02 类别:IOS开发

uitableview处理section的不悬浮,禁止section停留的方法
 
//
//  ViewController.m
//  qwerfresa
//
//  Created by  mac11 on 15-1-4.
//  Copyright (c) 2015 HYL. All rights reserved.
//
 
#import "ViewController.h"
 
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSArray * array;
     NSArray * arrayb;
}
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
    arrayb = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"g", nil];
    tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    tableview.delegate =self;
    tableview.dataSource =self;
    [self.view addSubview:tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
    return [array count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
    view.backgroundColor = [UIColor orangeColor];
    [tableView addSubview:view];
    
    
    UILabel *tmpHintLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 120, 20)];
    tmpHintLabel.backgroundColor = [UIColor clearColor];
//    tmpHintLabel.font = [UIFont fontWithName:TITLE_FONT size:NAV_BUTTON_SIZE];
//    tmpHintLabel.textColor = [];
    tmpHintLabel.text = [array objectAtIndex:section];
    tmpHintLabel.textAlignment = NSTextAlignmentLeft;
    [view addSubview:tmpHintLabel];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellditife= @"Cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellditife];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellditife];
    }
    cell.textLabel.text = [arrayb objectAtIndex:indexPath.row];
    return cell;
}

//uitableview处理section的不悬浮,禁止section停留的方法,主要是这段代码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 50;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end

本文为原创,转载请注明一下   转载于(www.wahenzan.com)(www.zhanbus.com)
本文地址:
http://www.wahenzan.com/a/mdev/ios/2015/0105/1412.html
或者地址:http://www.zhanbus.com/a/mdev/ios/2015/0105/1412.html
 
猜你会喜欢....

Copyright © 2015 www.wahenzan.com 哇!很赞 版权所有 浙ICP备14030256号-1 Power by DedeCms

浙公网安备 33010602005986号

声明:本站所有文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除 网站管理员:758763728

360网站安全检测平台