我困在一个小问题上。假设我有一个设备列表,分布在不同的位置。我在表格列表中输出所有这些设备。其中一些设备碰巧具有相同的位置。 是否有可能通过格式化这些单元格的粗体/双线来以某种方式对这些表单元格进行分组? 我知道多个自定义单元格的可能性,但我希望有人有一个更简单的方法:) 谢谢!分组一些表格单元格
0
A
回答
1
如果你想要的东西像下面
下面的代码添加到您的普通的tableview和每个位置返回部分按你的位置和行数,按您的设备的数量
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 5.0;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 2)];
view.backgroundColor = [UIColor blackColor];
return view;
}
0
1
不知道我理解你的问题,但你可以根据某些数据自定义任何单元格以寻找你想要的方式。
比方说,你设置你的设备的名称和位置,这样一个数组:
// keys in your device object
NSArray *aKeys = [NSArray arrayWithObjects:@"name", @"location", nil];
// 1st device (in location 1)
NSDictionary *device1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Device 1", @"Location 1", nil] forKeys:aKeys];
// 2nd device (in location 2)
NSDictionary *device2 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Device 2", @"Location 2", nil] forKeys:aKeys];
// 3rd device (in location 1 like device 1)
NSDictionary *device3 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Device 3", @"Location 1", nil] forKeys:aKeys];
// array of devices
NSArray *aDevices = [NSArray arrayWithObjects:device1, device2, device3, nil];
在你的tableView:(UITableView的*)电视 的cellForRowAtIndexPath:(NSIndexPath *)indexPath方法,你可以再检查并突出显示每个类型的位置。在这种情况下,我只是要一个彩色条添加到依赖于位置的颜色变化,像这样的小区的边缘:
if([[aDevices objectAtIndex:indexPath.row] objectForKey:@"location"] == @"Location 1"){
// if location is Location 1 then we'll add an ORANGE colored strip to the left indicating location 1
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"location1Cell"];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:@"location1Cell"] autorelease];
// colored strip
UIView *vwLoc = [[[UIView alloc]
initWithFrame:CGRectMake(0.0, 0.0, 5.0, 20.0)] autorelease];
[vwLoc setBackgroundColor:[UIColor orangeColor]];
[cell.contentView addSubview:vwLoc];
}
} else if([[aDevices objectAtIndex:indexPath.row] objectForKey:@"location"] == @"Location 2"){
// if location is Location 2 then we'll add an YELLOW colored strip to the left indicating location 2
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"location2Cell"];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:@"location2Cell"] autorelease];
// colored strip
UIView *vwLoc = [[[UIView alloc]
initWithFrame:CGRectMake(0.0, 0.0, 5.0, 20.0)] autorelease];
[vwLoc setBackgroundColor:[UIColor yellowColor]];
[cell.contentView addSubview:vwLoc];
}
}
// if location 3, location 4, etc. ...
+0
是的,这也是我的第一个想法,虽然Iphone_bharat发布的建议正是我正在寻找的! :) 非常感谢你的帮助 ;) – Joetjah 2011-04-04 09:47:32
相关问题
- 1. 动态分组表格单元格
- 2. XSLT总分组表格单元格
- 3. 自定义分组表格单元格
- 4. 安装一个按钮分组的表格单元格
- 5. 分组表视图 - 圆角单元格?
- 6. 组织模式表单元格分形
- 7. UITableView分组单元格
- 8. XtraGrid单元格分组
- 9. jquery分表单元格
- 10. 表格单元格不分开
- 11. 表格单元格划分PHP
- 12. iReport单元格跨越表格组件
- 13. 表格单元格的多维数组
- 14. JSF组件关闭表格单元格
- 15. 为表格单元分配一个id?
- 16. 表格单元格
- 17. 表格单元格
- 18. 表格单元格
- 19. 表格单元格
- 20. 表格单元格
- 21. Swing:为一些单元格使用粗体表格的TableCellRenderer
- 22. 通过CSS在表格中嵌入一些单元格
- 23. 单元格内容分配给非单元格数组对象
- 24. HTML表格单元格 - 隐藏一个单元格
- 25. 分组表格视图 - 实现选择哪个单元格
- 26. 分组表格视图单元格不加载
- 27. 将UIImageView或UIView添加到分组表格的单元格
- 28. 带分组单元格的CSS表格布局?
- 29. 将数组分组到单元格
- 30. 分组tableViewCell - 设置分组表格单元格的背景后没有圆角
该死的,好想法! – Joetjah 2011-04-04 09:46:21