tableview好友列表的實(shí)現(xiàn)

收縮

9596797.png

展開(kāi)

11311111.png
tableview 的section的協(xié)議方法 (避免重用問(wèn)題 可以 自定義一個(gè)類繼承于UITableViewHeaderFooterView 給他設(shè)置屬性,參照tableview的cell一樣賦值)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    /*
     標(biāo)題label + 分割線 + button
     */
    UITableViewHeaderFooterView *heaerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HEADERID];
    
    if (!heaerView) {
        heaerView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:HEADERID];
    }
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kWidth - 64, 64)];
        //標(biāo)題賦值
        titleLabel.text = _dataSource[section][0][@"techniquesType"];
        titleLabel.font = [UIFont boldSystemFontOfSize:22];
        
        UILabel *linelabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 63, kWidth - 20, 1)];
        linelabel.backgroundColor = [UIColor lightGrayColor];
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(kWidth - 54, 10, 44, 43)];
        button.backgroundColor = [UIColor redColor];
        button.tag = 100 + section;
        //判斷里面有值與否 來(lái)控制button的狀態(tài)
        if ([_dict objectForKey:[NSString stringWithFormat:@"%ld",section]]) {
            button.selected = YES;
        }else{
            button.selected = NO;
        }
      
        [button setImage:[UIImage imageNamed:@"inter_open"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"inter_close"] forState:UIControlStateSelected];
        [button addTarget:self action:@selector(action_sectionbutton:) forControlEvents:UIControlEventTouchUpInside];
        [heaerView addSubview:titleLabel];
        [heaerView addSubview:linelabel];
        [heaerView addSubview:button];
        heaerView.contentView.backgroundColor = [UIColor whiteColor];
        
    return heaerView;
}
收縮展開(kāi)的點(diǎn)擊事件
- (void)action_sectionbutton:(UIButton *)sender{
    if (!_dict) {
        _dict = [NSMutableDictionary dictionary];
    }
    NSString *key= [NSString stringWithFormat:@"%ld",sender.tag - 100];
    if (![_dict objectForKey:key]) {
        [_dict setObject:@"1" forKey:key];
    }else{
        [_dict removeObjectForKey:key];
    }
 //刷新某一個(gè)section
    [self.tableview reloadSections:[NSIndexSet indexSetWithIndex:sender.tag - 100] withRowAnimation:UITableViewRowAnimationFade];
}

tableview的section高度的協(xié)議方法
//row的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([_dict objectForKey:[NSString stringWithFormat:@"%ld",indexPath.section]]) {
         return 44.0;
    }else{
        return 0;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容