Ios 在UITableView的部分中添加小节
搜索了很多,但都是徒劳的。我有一个嵌套的Ios 在UITableView的部分中添加小节,ios,objective-c,uitableview,Ios,Objective C,Uitableview,搜索了很多,但都是徒劳的。我有一个嵌套的NSMutableArray的NSMutableDictionary。我希望在UITableView的节中有节。以下是我的阵列: <__NSArrayM 0x7ffe4267efb0>( { "group_title" = "Seller Information"; "group_values" = ( { key = "First Name";
NSMutableArray
的NSMutableDictionary
。我希望在UITableView
的节中有节。以下是我的阵列:
<__NSArrayM 0x7ffe4267efb0>(
{
"group_title" = "Seller Information";
"group_values" = (
{
key = "First Name";
value = test;
},
{
key = "Last Name";
value = testl;
}
);
},
{
"group_title" = "Buyer Information";
"group_values" = (
{
key = "First Name";
value = Demo1;
},
{
key = "Last Name";
value = Demo;
}
);
},
{
"group_title" = "Transaction Information";
"group_values" = (
{
key = Status;
value = Active;
},
{
key = "MLS #";
value = "15-284";
},
{
key = Address;
value = "1101 Fargo Ave";
},
{
key = County;
value = Dickinson;
},
{
key = Zipcode;
value = 51360;
},
{
key = Contingencies;
value = (
{
key = "General Inspection";
value = (
{
key = "Contingency Verbiage";
value = "Inspection Results and balance of this paragraph";
}
);
},
{
key = "New Construction";
value = (
{
key = "Contingency Group";
value = "If Required";
},
{
key = "Days Until Due";
value = 5;
}
);
}
);
}
);
}
)
我知道我只需要将子部分作为单元进行操作,但不确定如何操作
如何访问CellForRowatineXpath
中的子部分
请帮忙。我如何解决和实施这个问题 您可以使用delegate方法
indentationlevelforrowatinexpath
向单元格添加缩进级别,因此如果要显示子节,只需返回一个NSInteger
值,例如1,返回值表示指定行的深度,以显示其在节中的层次位置
到目前为止,返回值应该是
Contingencies // sub-section title - 1
General Inspection // sub-sub-section title - 2
Contingency Verbiage //value - 3
New Construction // sub-sub-section title - 2
Contingency Group //value - 3
Days Until Due //value - 3
添加示例代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//Set the indentation width, so that each indentation level width will increase by it.
cell.indentationWidth = 5;
//Show the value from corresponding indexPath
NSArray *arr = [[dictData valueForKey:@"group_values"] objectAtIndex:indexPath.section];
NSMutableArray *items = [NSMutableArray arrayWithArray:arr];
// For second level section headers
for (id row in arr) {
if([[row objectForKey:@"value"] isKindOfClass:[NSMutableArray class]]) {
[items addObjectsFromArray:[row valueForKey:@"value"]];
}
}
NSDictionary *item = items[indexPath.row]
cell.textLabel.text = item[@"key"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
//Retrive the right indentation for item at indexPath
NSArray *arr = [[dictData valueForKey:@"group_values"] objectAtIndex:indexPath.section];
if (indexPath.row < arr.count) {
return 0
}
// For second level section headers
return 1
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@“cell”forIndexPath:indexPath];
//设置缩进宽度,使每个缩进级别的宽度增加一倍。
cell.indicationwidth=5;
//显示来自相应索引XPath的值
NSArray*arr=[[dictData valueForKey:@“group_values”]objectAtIndex:indexPath.section];
NSMUTABLEARRY*项=[NSMUTABLEARRY arrayWithArray:arr];
//对于第二级节标题
用于(arr中的id行){
如果([[row objectForKey:@“value”]是KindofClass:[NSMutableArray类]]){
[items addObjectsFromArray:[行值forkey:@“值”];
}
}
NSDictionary*item=items[indexPath.row]
cell.textlab.text=项[@“键”];
返回单元;
}
-(NSInteger)tableView:(UITableView*)tableView indentationLevelForRowAtIndexPath:(nsindepath*)indepath{
//在indexPath处检索项的正确缩进
NSArray*arr=[[dictData valueForKey:@“group_values”]objectAtIndex:indexPath.section];
if(indexPath.row
谢谢,但是我应该在cellforrowatinexpath
中为小节写些什么呢?您不必在cellforrowatinexpath
中做任何特定的操作,因为indentationlevelforrowatinexpath
将根据定义的小节对单元格进行缩进。您能给我一些示例代码吗?我不知道如何在我的代码中包含这一点。我已经在问题中给出了我的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//Set the indentation width, so that each indentation level width will increase by it.
cell.indentationWidth = 5;
//Show the value from corresponding indexPath
NSArray *arr = [[dictData valueForKey:@"group_values"] objectAtIndex:indexPath.section];
NSMutableArray *items = [NSMutableArray arrayWithArray:arr];
// For second level section headers
for (id row in arr) {
if([[row objectForKey:@"value"] isKindOfClass:[NSMutableArray class]]) {
[items addObjectsFromArray:[row valueForKey:@"value"]];
}
}
NSDictionary *item = items[indexPath.row]
cell.textLabel.text = item[@"key"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
//Retrive the right indentation for item at indexPath
NSArray *arr = [[dictData valueForKey:@"group_values"] objectAtIndex:indexPath.section];
if (indexPath.row < arr.count) {
return 0
}
// For second level section headers
return 1
}