TabelViewCell展开

//从服务器请求回数据

 if ([run_num intValue] == 1) {

            

            NSArray *arr = [dictionary valueForKey:@"key"];

            [self.Arrdata removeAllObjects];

            

            

            for(NSDictionary *dic in arr){

            

                NSMutableDictionary *mudic=[NSMutableDictionary dictionaryWithDictionary:dic];

                [mudic setObject:[NSNumber numberWithBool:NO] forKey:@"open"];

                [self.Arrdata addObject:mudic];

            }

            

            

            [self.tableview reloadData];

            

//TabelView代理方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 44;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return self.Arrdata.count;

}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

  

    

    NSDictionary *dic =[self.Arrdata objectAtIndex:section];

    return [dic valueForKey:@"name"];

    


    

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    NSDictionary *dic=self.Arrdata[section];

    if([[dic objectForKey:@"open"] boolValue]){

        //展开

        

        return [(NSArray *)[dic objectForKey:@"item"] count];

    }else{

        //关闭

        return 0;

    }

    

}


-(float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 5;

}

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

    

    NSDictionary *dic =[self.Arrdata objectAtIndex:section];

    UIButton *button=[MyControl createButtonWithFrame:CGRectMake(0, 0, ScrrenWidth, 50) ImageName:nil Target:self Action:@selector(buttonClick:) Title:[dic valueForKey:@"name"]];

    button.tag=section+300;

    

    

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

    button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

    button.contentMode=UIViewContentModeLeft;

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    button.backgroundColor=[UIColor whiteColor];

    

    UIImageView *rightView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Jright"] highlightedImage:[UIImage imageNamed:@"Jbottom"]];

    BOOL isopen=[[dic objectForKey:@"open"] boolValue];

    rightView.highlighted=isopen;

    rightView.frame=CGRectMake(ScrrenWidth-30, 20, 15, 15);

    rightView.tag=998;

    [button addSubview:rightView];

    

    return button;

}

#pragma mark---------头部师徒点击

-(void)buttonClick:(UIButton *)btn

{

    

    NSDictionary *dic =[self.Arrdata objectAtIndex:btn.tag-300];

    

    BOOL isopen=[[dic objectForKey:@"open"] boolValue];

    

    UIImageView *rightView=(UIImageView *)[btn viewWithTag:998];

    rightView.highlighted=!isopen;

    

    [dic setValue:[NSNumber numberWithBool:!isopen] forKey:@"open"];

    [self.tableview reloadSections:[NSIndexSet indexSetWithIndex:btn.tag-300] withRowAnimation:UITableViewRowAnimationFade];

    

    

    

}

// 设置section的高度

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

{

    return 50;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *strcelltag =@"cell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strcelltag];

    

    if (cell== nil) {

        

        NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"SelectQuestionCell" owner:nil options:nil];

        cell = [arr objectAtIndex:0];

        

        

        

    }

    

    UILabel *labtitle = (UILabel *)[cell viewWithTag:21];

    

   

    NSDictionary *dict = [self.Arrdata objectAtIndex:indexPath.section];

    NSArray *arr = [dict valueForKey:@"item"];

    

    labtitle.text = [arr objectAtIndex:indexPath.row];

    

        


    return cell;

    

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    

    [self.tableview deselectRowAtIndexPath:indexPath animated:YES];

    NSDictionary *dict = [self.Arrdata objectAtIndex:indexPath.section];

    NSArray *arr = [dict valueForKey:@"item"];

    HomeSearchListViewController *vc=[HomeSearchListViewController new];

    vc.query_type=@"question";

    vc.title=[arr objectAtIndex:indexPath.row];

    vc.searchStr = vc.title;

    [self.navigationController pushViewController:vc animated:YES];

  }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值