1
的部分小節搜索了很多,但一切都是徒勞。我有一個嵌套的NSMutableDictionary
NSMutableArray
。我想在UITableView
的部分內有章節。以下是我的數組:加入的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;
}
);
}
);
}
);
}
)
如果經過上面的數組,然後group_title
是我想要的節數。 key
,「值」在group_values
是在每個部分的行數。
對於關鍵Contingencies
,有嵌套的數據。所以我想顯示它如下:
Transaction Information // section title
Contingencies // sub-section title
General Inspection // sub-sub-section title
Contingency Verbiage //value
New Construction // sub-sub-section title
Contingency Group //value
Days Until Due //value
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [dictData count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSMutableArray *arr = [[dictData valueForKey:@"group_values"] objectAtIndex:section];
NSUInteger numberOfRows = arr.count; // For second level section headers
for (id row in arr) {
if([[row objectForKey:@"value"] isKindOfClass:[NSMutableArray class]]) {
numberOfRows += [[row valueForKey:@"value"] count];
}
}
return numberOfRows;
}
我知道我必須作爲單元操作的子部分,但不知道如何做到這一點。
如何訪問cellforrowatindexpath
中的子部分?
請幫忙。我如何解決和實施這個?
謝謝,但是我在'cellForRowAtIndexPath'中爲子部分寫了什麼? – z22
因爲'indentationLevelForRowAtIndexPath'將根據定義的子部分爲單元格提供縮進,所以您不必在'cellForRowAtIndexPath'中執行任何特定操作。 – deoKasuhal
你能告訴我一些示例代碼嗎?我不知道如何將這個包含在我的代碼中。我已經在問題中給出了我的代碼。 – z22