• 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 = [NSArrayarrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
        arrayb = [NSArrayarrayWithObjects:@"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:UITableViewCellStyleDefaultreuseIdentifier: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
  • 相关阅读:
    在 《超过 光速 的 方法》 里 的 回复
    超过 光速 的 方法
    在 《我对 相对论 提出了一个 修正,名为 “K氏修正”》 里 的 回复
    我对 相对论 提出了一个 修正,名为 “K氏修正”
    input 只读不能修改
    获取父iframe的高宽
    indexOf ie下的兼容问题
    英文单词自动换行
    textarea 限制字数
    js判断输入框的范围,并且只能输入数字
  • 原文地址:https://www.cnblogs.com/kexiaozhu/p/5379386.html
Copyright © 2020-2023  润新知