IOS列表实现动态多列
2024-10-09 21:38:48
、
//图片列表
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 = ;
}
}
最新文章
- HTML中的select只读
- java调用Linux命令报错:java.io.IOException: Cannot run program ";ps";: CreateProcess error=2, ?????????
- 2015年百度之星初赛(1) --- D KPI
- HTTP基础(一):如何使用浏览器network查看请求和响应的信息
- DedeCms 5.x 本地文件包含漏洞(respond方法)
- git 初次使用
- 05---JSON学习(Java)
- Android开源项目发现--- 效率开发工具篇(持续更新)
- SQL Server 2008中数据压缩
- Nmap Snote
- 64位调试器花费的时间比预期的要长(A 64-bit debugging operation is taking longer than expected)
- Moq &; RhinoMocks
- 河南多校大一训练赛 D
- 课堂博客-----TreeView+++++XML形成博客
- POJ 2359 Questions(约瑟夫环——数学解法)
- 跟我学ASP.NET MVC之二:第一个ASP.NET MVC程序
- SOUI新组件SIpcObject介绍
- python + PyQt5 实现 简易计算器
- XGBOOST应用及调参示例
- 自学Aruba3.2-Aruba配置架构-Virtual AP配置要点