• IOS列表实现动态多列


    1 //图片列表
    2 NSMutableArray *pictureList;
    3 //分组列表
    4 NSMutableArray *indexArr;
     1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     2 {
     3     static NSString *picWallItemView = @"picWallItemView";
     4     UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:picWallItemView];
     5     if (cell == nil) {
     6         cell = [[[UITableViewCell alloc]
     7                  initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self tableView:self.tableView heightForRowAtIndexPath:indexPath])] autorelease];
     8     }
     9     int num = [[indexArr objectAtIndex:indexPath.row] intValue];
    10     int index = 0;
    11     for (int i = 0; i < indexPath.row; i++) {
    12         index += [[indexArr objectAtIndex:i] intValue];
    13     }
    14     
    15     float tmpWidth = self.view.frame.size.width / num;
    16     float tmpHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPath];
    17     float left = 0;
    18     for (int i = 0; i < num; i ++) {
    19         left = i * tmpWidth;
    20         PicWallItemView *itemView = [[PicWallItemView alloc] initWithFrame:CGRectMake(left, 0, tmpWidth, tmpHeight)];
    21         itemView.delegate = self;
    22         NSDictionary *jsonDic = [pictureList objectAtIndex:index];
    23         PicWallItemTo *item = [PicWallItemTo fromDictionary:jsonDic];
    24         [itemView setIndentationWidth:5];
    25         [itemView reloadData:item];
    26         [cell addSubview:itemView];
    27         [itemView setFrame:CGRectMake(left, 0, tmpWidth, tmpHeight)];
    28         [itemView release];
    29         index++;
    30     }
    31     return cell;
    32 }

    在接收数据的地方,对数据进行分组。

     1         NSArray *arr = [obj objectForKey:MSG_DETALIST];
     2         
     3         NSUInteger total = [arr count];
     4         while (total > 0) {
     5             int num = arc4random() % 3 + 1;
     6             if(total > num){
     7                 [indexArr addObject:[NSNumber numberWithInt:num]];
     8                 total -= num;
     9             } else {
    10                 [indexArr addObject:[NSNumber numberWithInt:total]];
    11                 total = 0;
    12             }
    13         }    

      

  • 相关阅读:
    linux 安装Python3
    MYSQL 字符集设置(终端的字符集)
    Linux LVM Logical Volume Management 逻辑卷的管理
    oracle 重命名和重定位数据文件(Oracle Renaming and Relocating Datafiles)
    Azkaban编译
    基于hive的transform实现自定义分隔符数据导出
    MapReduce优化设置
    hive.groupby.skewindata环境变量与负载均衡
    hive的基本操作
    Shell 数组的定义和使用
  • 原文地址:https://www.cnblogs.com/warrior/p/3296038.html
Copyright © 2020-2023  润新知