zoukankan      html  css  js  c++  java
  • IOS 7 viewForHeaderInSection 的section从1开始而不是从0开始

    【问题】

      (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 方法中的section貌似从1开始而不是从0



    【思路】

    程序中虽然设置了 self.tableView.sectionHeaderHeight  =20 

    还还是是不行 viewForHeaderInSection 中的section始终还是从1开始。

    于是我发现, 如果你使用方法:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

    {

        return 40;

    }

    就从0开始啦。 

     

    尼玛真吭 IOS7的新特性,其实 self.tableView.sectionHeaderHeight  =20 这种效率远远比方法要快。如果不存在特殊需求大家还是直接设置属性来吧。

     

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 40;
    }
    
    - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, tableView.frame.size.width, 20)];
        label.font = [UIFont systemFontOfSize:16.0f];  //UILabel的字体大小
        label.numberOfLines = 0;  //必须定义这个属性,否则UILabel不会换行
        label.textColor = CR_RGBCOLOR(170, 170, 170);
        label.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
        [label setBackgroundColor:[UIColor clearColor]];
        label.text = self.sectionTitles[section];
        [headerView setBackgroundColor:[UIColor clearColor]];
        [headerView addSubview:label];
        return  headerView;
    }
    
    - (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {
    
        return [[CRCustomFooter alloc] init];
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSUInteger section = indexPath.section;
        NSUInteger row = indexPath.row;
        
        if(section == 1){
            if (row == 0) {
                [self recommendToFriends];
                [tableView deselectRowAtIndexPath:indexPath animated:YES];
            }else if(row == 1){
                [self sendFeedback];
                [tableView deselectRowAtIndexPath:indexPath animated:YES];
            }else if(row == 2){
                [self rateApp];
                [tableView deselectRowAtIndexPath:indexPath animated:YES];
            }else{
            }
        }
    }
  • 相关阅读:
    基于Grafana+SimpleJson的灵活报表解决方案
    Scala安装时的坑
    Windows批量添加防火墙例外端口
    VMware与Hyper-V
    InfluxDB:cannot use field in group by clause
    .Net版InfluxDB客户端使用时的一些坑
    KafkaManager中Group下不显示对应Topic的解决方案
    Linux下查看Go语言软件运行情况
    Flink升级到1.4版本遇到的坑
    spring cloud(一)带你进入分布式
  • 原文地址:https://www.cnblogs.com/rubick/p/3725748.html
Copyright © 2011-2022 走看看