QQ分组思路

来源:互联网 发布:知乎 扎比 编辑:程序博客网 时间:2024/04/30 03:17

一、定义一个全局变量数组 dataArray

二、有数据源字典,字典里面有:1、section的大标题,用@“name”标示,2、有一数组,里面装了row的小标题,整个数组用@“subname”标示

三、把字典放到全局变量数组 dataArray中

四、

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 在这个函数中,加上button

五、在button的点击事件中,操作展开/合上操作,重点是在reloadtableview的时候,根据section所取字典的expand值来,决定row的行数是几行,则game completed,具体的是:在dataArray中,

NSMutableDictionary* d = [dataArrayobjectAtIndex:section];

在字典中加上是否展开这一标示

//对指定的节进行展开/折叠操作

-(void)btnClickCollapseOrExpand:(int)section{

    

   Boolean expanded = NO;

   NSMutableDictionary* d = [dataArrayobjectAtIndex:section];

    

    //若本节model中的“expanded”属性不为空,则取出来

   if([d objectForKey:@"expanded"]!=nil)

        expanded=[[dobjectForKey:@"expanded"]intValue];

 

   NSLog(@"expand = %d",expanded);

   //若原来是折叠的则展开,若原来是展开的则折叠

    [d setObject:[NSNumbernumberWithBool:!expanded]forKey:@"expanded"];

}


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

{

   if (![selfisExpanded:section])

       return 0;

   NSDictionary* d=[dataArrayobjectAtIndex:section];

    return [[dobjectForKey:@"user"]count];

}


//返回指定节的“expanded”

-(Boolean)isExpanded:(int)section{

   Boolean expanded = NO;

   NSMutableDictionary* dic = [dataArrayobjectAtIndex:section];

    //若本节model中的“expanded”属性不为空,则取出来

   if([dic objectForKey:@"expanded"]!=nil)

        expanded=[[dicobjectForKey:@"expanded"]intValue];

   return expanded;

}



0 0
原创粉丝点击