zoukankan      html  css  js  c++  java
  • 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         }    

      

  • 相关阅读:
    Codeforces 512E
    UOJ #36 -【清华集训2014】玛里苟斯(线性基+暴搜)
    Codeforces 1188E
    洛谷 P7163
    C++ Boost库 操作日期与时间
    C/C++ 搜索缝隙并插入ShellCode
    线性代数学习之正交性,标准正交矩阵和投影
    洛谷 P5851 [USACO19DEC]Greedy Pie Eaters P(区间dp)
    洛谷 [NOIP2009 普及组] 道路游戏(dp)
    洛谷 P2890 [USACO07OPEN]Cheapest Palindrome G(区间dp)
  • 原文地址:https://www.cnblogs.com/warrior/p/3296038.html
Copyright © 2011-2022 走看看