• 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{
            }
        }
    }
  • 相关阅读:
    fastjson1.2.22-1.2.24 反序列化命令执行实践测试
    Spring boot JdbcTemplate sql注入测试
    java反序列化命令执行测试实践
    SpringBoot 整合mybatis SQL注入漏洞实践
    SpringBoot整合mybatis入门
    python函数默认参数为可变对象的理解
    python笔记
    python
    python面向对象
    ICMP
  • 原文地址:https://www.cnblogs.com/rubick/p/3725748.html
Copyright © 2020-2023  润新知