我困在一個小問題上。假設我有一個設備列表,分佈在不同的位置。我在表格列表中輸出所有這些設備。其中一些設備碰巧具有相同的位置。 是否有可能通過格式化這些單元格的粗體/雙線來以某種方式對這些表單元格進行分組? 我知道多個自定義單元格的可能性,但我希望有人有一個更簡單的方法:) 謝謝!分組一些表格單元格
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. XSLT總分組表格單元格
- 2. 分組表視圖 - 圓角單元格?
- 3. 組織模式表單元格分形
- 4. XtraGrid單元格分組
- 5. UITableView分組單元格
- 6. jquery分表單元格
- 7. 表格單元格的多維數組
- 8. 爲表格單元分配一個id?
- 9. 表格單元格
- 10. 表格單元格
- 11. Swing:爲一些單元格使用粗體表格的TableCellRenderer
- 12. 單元格內容分配給非單元格數組對象
- 13. HTML表格單元格 - 隱藏一個單元格
- 14. Mapkit用於分組表格單元格並擴展圓角
- 15. 帶分組單元格的CSS表格佈局?
- 16. 分組表格視圖單元格不加載
- 17. 爲表格單元格分配數組值
- 18. 顯示錶格單元格不一致。
- 19. JQuery的選擇表格單元格,下一個表格單元有條件
- 20. 表格單元格對齊
- 21. 表格單元格很大
- 22. 與表格單元格
- 23. FindControl表格單元格
- 24. Html表格單元格值
- 25. 選擇表格單元格
- 26. 偏移表格單元格
- 27. 溢出表格單元格
- 28. jeditable表格單元格
- 29. 在表格單元格
- 30. 修改表格單元格
該死的,好想法! – Joetjah 2011-04-04 09:46:21