qq好友列表(tableview的使用)

//

//  ViewController.m

//  qq好友列表

//

//  Created by 洪福清 on 2016/12/13.

//  Copyright © 2016 BJTYL. All rights reserved.

//


#import "ViewController.h"

#import "PersonModel.h"

#import "GroupModel.h"

#import "MyTableViewCell.h"

#import "MyHeadView.h"


@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,MyHeadViewDelegate>


@property (strong,nonatomic)UITableView *tableView;


@property (strong,nonatomic)NSArray *grupArray;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

 

//下载地址https://github.com/homeabc/QQFriend

    self.view.backgroundColor = [UIColorwhiteColor];

    [self.viewaddSubview:self.tableView];

    

    

}



-(NSArray *)grupArray

{

    if (_grupArray ==nil) {

        NSString *path = [[NSBundlemainBundle]pathForResource:@"test.plist"ofType:nil];

        NSArray *arrDict = [NSArrayarrayWithContentsOfFile:path];

        

        

        NSMutableArray *arrayModels = [NSMutableArrayarray];

        for (NSDictionary *dictin arrDict) {

            GroupModel *models = [GroupModelGroupWithDict:dict];

            [arrayModels addObject:models];

        }

        _grupArray = arrayModels;

    }

    return_grupArray;

  

}




-(UITableView *)tableView

{

    if (_tableView ==nil) {

        _tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,64,375, 667-64)style:UITableViewStylePlain];

        _tableView.delegate =self;

        _tableView.dataSource =self;

        _tableView.bounces =NO;

        _tableView.showsHorizontalScrollIndicator =NO;

        _tableView.showsVerticalScrollIndicator =NO;

        _tableView.separatorStyle =UITableViewCellSeparatorStyleNone;

        _tableView.sectionHeaderHeight =44;

        

    }

    return_tableView;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    returnself.grupArray.count;

}



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

{

    

    // 在这个方法中。要根据当前组的状态)是否是展开)

    

    GroupModel *models =self.grupArray[section];

    if (models.isVisible) {

         return models.friedns.count;

    }

    else

    {

        return0;

    }


}

static NSString *cellId =@"cellId";


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

{

    MyTableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellId];

    if (!cell) {

        cell = [[MyTableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellId];

    }

    

    GroupModel *group =self.grupArray[indexPath.section];

    

    PersonModel *friend = group.friedns[indexPath.row];

    

    cell.models = friend;

    

    return cell;

    

}


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

{

    //不要在这个方法中直接创建一个uivew对象返回。因为这样无法实现重用

    GroupModel *group =self.grupArray[section];


    

    MyHeadView *headView = [MyHeadViewheaderViewWithTableView:tableView];

    

    //创建UITableViewHeaderFooterView

//    UITableViewHeaderFooterView *headView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellId];

//    if (headView == nil) {

//        headView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:cellId];

//    }

    

    headView.models = group;

    headView.delegate =self;

    headView.tag = section;

    


    //在刚刚创建好的header  view中获取的header viewframe都是0

    

    return headView;

    

    

}



- (void)headViewDidClickTitleButton:(MyHeadView *)headView

{

    NSIndexSet *idxSet = [NSIndexSetindexSetWithIndex:headView.tag];

    [self.tableViewreloadSections:idxSetwithRowAnimation:UITableViewRowAnimationFade];

}















@end


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值