zoukankan      html  css  js  c++  java
  • 刷新tableView 保持头部视图 不变

    1. 声明全局变量

      UIView *headView; 表头部View

        UIButton *financeBtn; //金融头条Btn

        UIButton *companyNewsBtn;//公司新闻Btn

    2.在viewDidLoad里面 

    - (void)viewDidLoad {

        [super viewDidLoad];

        float screenWidth = kUIScreenWidth -70;

        financeBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        [financeBtn setTitle:@"金融头条" forState:UIControlStateNormal];

        [financeBtn.titleLabel setFont:[UIFont fontWithName:kPingFang_Medium size:14]];

        [financeBtn setFrame:CGRectMake(screenWidth/4-40, 12, 80, 25)];

        [financeBtn setTitleColor:[CommonFunctions colorWithHex:0x11a1b4] forState:UIControlStateNormal];

        [financeBtn setTag:222];

        [financeBtn addTarget:self action:@selector(companyNewsBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        companyNewsBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        [companyNewsBtn setTitle:@"公司新闻" forState:UIControlStateNormal];

        [companyNewsBtn.titleLabel setFont:[UIFont fontWithName:kPingFang_Medium size:14]];

        [companyNewsBtn setFrame:CGRectMake((screenWidth/2)+(screenWidth/4-40), 12, 80, 25)];

        [companyNewsBtn setTitleColor:[CommonFunctions colorWithHex:0x999999] forState:UIControlStateNormal];

        [companyNewsBtn addTarget:self action:@selector(companyNewsBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        [companyNewsBtn setTag:333];

    }

    3.  区头设置    在方法里面判断不让按钮循环创建

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

         headView = [[UIView alloc] initWithFrame:CGRectMake(0, -1, kUIScreenWidth, 69)];

        headView.backgroundColor = [UIColor whiteColor];

       if(section == 0) {

            UIButton *mergeBtn = (UIButton *)[self.view viewWithTag:222];

            if (mergeBtn == nil) {

                [headView addSubview:financeBtn];

                [headView addSubview:companyNewsBtn];

            }

        }

    return headView;

    4. 实现按钮的点击方法就OK了

    #pragma mark  金融头条和公司新闻 Btn

    - (void)companyNewsBtnClick:(UIButton *)sender {

       float screenWidth = kUIScreenWidth -70;

        UIButton *changeBtn = (UIButton *)[self.view viewWithTag:sender.tag];

        [changeBtn setTitleColor:[CommonFunctions colorWithHex:0x11a1b4] forState:UIControlStateNormal];

        if (sender.tag == 222) {

            NSLog(@"金融头条");

            picImg.frame = CGRectMake(screenWidth/4-40, -1, 80, 4);

            [companyNewsBtn setTitleColor:[CommonFunctions colorWithHex:0x999999] forState:UIControlStateNormal];

        }else if (sender.tag == 333) {

            NSLog(@"公司新闻");

            picImg.frame = CGRectMake((screenWidth/2)+(screenWidth/4-40), -1, 80, 4);

            [financeBtn setTitleColor:[CommonFunctions colorWithHex:0x999999] forState:UIControlStateNormal];

        }

    }

     

    效果图 如下:

  • 相关阅读:
    LeetCode.5-最长回文子串(Longest Palindromic Substring)
    LeetCode.3-最长无重复字符子串(Longest Substring Without Repeating Characters)
    2013 最新的 play web framework 版本 1.2.3 框架学习文档整理
    play framework学习笔记之 模板引擎
    C# 枚举、字符串、值的相互转换
    styleCop
    配置VS代码生成工具ReSharper快捷键
    StackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's All About Performance
    开启Windows Server 2008 R2上帝模式
    微信支付实战(与支付宝和其他一些支付有些不一样)
  • 原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/6931792.html
Copyright © 2011-2022 走看看