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         }    

      

  • 相关阅读:
    particcles.js in 安卓WebView
    PDF.js 主页样式以及获取流
    Oracle授权A中的表给B
    安卓Response 获取body的正确方式
    android.util.Base64 和 org.apache.commons.codec.binary.Base64
    DAY62-前端入门-javascript(九)jQurey高级
    DAY61-前端入门-javascript(八)jQurey
    DAY60-前端入门-javascript(七)JS动画 | JS盒模型 | DOM | BOM
    DAY59-前端入门-javascript(六)JS事件
    DAY58-前端入门-javascript(五)JS常用类
  • 原文地址:https://www.cnblogs.com/warrior/p/3296038.html
Copyright © 2011-2022 走看看