、
//图片列表
NSMutableArray *pictureList;
//分组列表
NSMutableArray *indexArr;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *picWallItemView = @"picWallItemView";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:picWallItemView];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectMake(, , self.view.frame.size.width, [self tableView:self.tableView heightForRowAtIndexPath:indexPath])] autorelease];
}
int num = [[indexArr objectAtIndex:indexPath.row] intValue];
int index = ;
for (int i = ; i < indexPath.row; i++) {
index += [[indexArr objectAtIndex:i] intValue];
} float tmpWidth = self.view.frame.size.width / num;
float tmpHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPath];
float left = ;
for (int i = ; i < num; i ++) {
left = i * tmpWidth;
PicWallItemView *itemView = [[PicWallItemView alloc] initWithFrame:CGRectMake(left, , tmpWidth, tmpHeight)];
itemView.delegate = self;
NSDictionary *jsonDic = [pictureList objectAtIndex:index];
PicWallItemTo *item = [PicWallItemTo fromDictionary:jsonDic];
[itemView setIndentationWidth:];
[itemView reloadData:item];
[cell addSubview:itemView];
[itemView setFrame:CGRectMake(left, , tmpWidth, tmpHeight)];
[itemView release];
index++;
}
return cell;
}
在接收数据的地方,对数据进行分组。
NSArray *arr = [obj objectForKey:MSG_DETALIST]; NSUInteger total = [arr count];
while (total > ) {
int num = arc4random() % + ;
if(total > num){
[indexArr addObject:[NSNumber numberWithInt:num]];
total -= num;
} else {
[indexArr addObject:[NSNumber numberWithInt:total]];
total = ;
}
}