QQ联系人界面tableview展开和收缩

闲着无聊.瞎写.目前貌似有点简单了...毕竟刚入门时困扰了好久...

#import "CeShiTableViewController.h"

@interface CeShiTableViewController ()
@property (nonatomic , strong) NSArray * titleAry;

@property (nonatomic , strong) NSArray *contentAry;

@property (nonatomic , strong) NSMutableArray *SelectAry;
@end

@implementation CeShiTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];
    self.titleAry = @[@"组1",@"组2",@"组3"];
    self.contentAry = @[@[@"123",@"1234",@"111",@"666",@"dsadasd",@"dasfsa",@"2年前第一次写觉得好难",@"2年后再写实在有点简单了"],@[@"2",@"222",@"2222222",@"21"],@[@"UI股",@"湿哒哒",@"多撒大所",@"大神的撒范德萨范德萨范德萨发",@"sfdsf",@"wfwfwef",@"fs"]];
    self.SelectAry = [@[@(0),@(0),@(0)]mutableCopy];
    
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.backgroundColor = [UIColor redColor];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return _titleAry.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    if ([self.SelectAry[section] isEqualToNumber:@(0)]) {//没点击
        return 0;
    }else
        
    return ((NSArray * )self.contentAry[section]).count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = self.contentAry[indexPath.section][indexPath.row];
    cell.backgroundColor = [UIColor yellowColor];
    // Configure the cell...
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIButton *headerBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    [headerBtn setTitle:self.titleAry[section] forState:UIControlStateNormal];
    headerBtn.tag = 1000 + section;
    [headerBtn addTarget:self action:@selector(ChangeNum:) forControlEvents:UIControlEventTouchUpInside];
    headerBtn.backgroundColor = [UIColor blackColor];
    return headerBtn;
}
- (void)ChangeNum:(UIButton *)sender{
    int i = (int)sender.tag - 1000;
  
    if ([self.SelectAry[i] isEqualToNumber:@(0)]) {//没展开
          [self.SelectAry replaceObjectAtIndex:i withObject:@(1)];//去展开
    }else//展开了
    {
        [self.SelectAry replaceObjectAtIndex:i withObject:@(0)];
    }
    //刷新tableview(区)
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:i] withRowAnimation: UITableViewRowAnimationFade];
  
    NSLog(@"点击数组%@",self.SelectAry);
    
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,923评论 25 709
  • 偶尔的格格不入会让我怀疑人生,怀疑自己做错了决定,但是我知道,不可能每个选择都是正确的,有些时候,我们必须面对,以...
    霁雪晴川阅读 556评论 0 0
  • 旅行,是心灵的阅读,而阅读,是心灵的旅行。无论哪种旅行,我想我都去不了!
    花开有声阅读 174评论 1 0
  • 街拍达人 Timer 穿搭主题 整身以灰色和蓝色为发想,连丹宁裤也是刻意选择有点灰色调的蓝,丹宁裤的蓝可以缓和大衣...
    STYLEMIXER阅读 1,628评论 2 3

友情链接更多精彩内容