如何使用多级部分正确显示uitableview中的嵌套数组数据 [英] how to display nested array data inside uitableview properly with Multiple level of Sections
问题描述
我有以下json数据
{
"Display_Selected List":
[
{
"product_name": "Product1",
"items":
[
{
"item_name": "SubItem1",
"specifications":
[
{
"list": [
{
"name": "Sp1"
},
{
"name": "Sp2"
}
],
"specification_name": "Specification Group 1"
},
{
"list": [
{
"name": "Sp3"
},
{
"name": "Sp4"
}
],
"specification_name": "Specification Group 2"
}
]
},
{
"item_name": "Sub Item2",
"specifications":
[
{
"list": [
{
"name": "Sp2"
}
],
"specification_name": "Specification Group 1"
},
{
"list": [
{
"name": "Sp3"
}
],
"specification_name": "Specification Group 2"
}
]
}
]
},
{
"product_name": "Product2",
"items":
[
{
"item_name": "Item1",
"specifications":
[
{
"list": [
{
"name": "Sp3"
},
{
"name": "Sp4"
}
],
"specification_name": "Specification Group 2"
}
]
}
]
}
]
}
根据设计要求,我必须在单个非常合适的视图中显示整个数据,例如关注
我已创建粗略设计,如下图所示
As per the design requirement i have to diplay this whole data in single uitable view like follow I have created rough design as shown in below image
我可以实现这一点通过
uita bleview
在uitableviewcell
内,但每Apple推荐
Apple不建议将表格视图添加为
作为其他可滚动的子视图对象
I can achieve this via
uitableview
insideuitableviewcell
but as per Apple recommendation Apple does not recommend table views to be added as subviews of other scrollable objects
现在我的问题是如何通过单个uitableview实现以下设计,并且根据我的json,所有内容都是动态的
Now my question is how can i achieve following design by single uitableview and and also as per my json all the content are dynamic
有没有人见过这样的东西?任何参考都会有所帮助。
Does anyone have seen something like this around ? Any reference would be helpful.
推荐答案
如果你不想使用 tableView
在 tableViewCell
内,您可以采用以下方法。
If you don't wish to use tableView
inside tableViewCell
, you could possible go by the following approach.
- 创建3个不同的单元格,第一个用于显示项目名称,第二个用于显示规范组名称,第三个用于显示规范项目(例如:Sp1,Sp2,..)
-
numberOfRowsInSection
将具有使用上述创建的单元格显示数据的正确计数。因此,numberOfRows应返回总计数,如rowsInSection =
项目数+每个项目中的规格数+每个项目的每个规格中的列表数 - 相应地更改数据源并进行条件检查,以便首先显示项目名称单元格,然后显示规范组名称的单元格,然后在每个规范中显示规范项目,然后显示下一个项目名称,依此类推。
- Create 3 different cells first one for showing item name, second one for showing the Specification group name and the third one for showing the specification items (eg: Sp1,Sp2,..)
numberOfRowsInSection
will have the correct count to show data using the above created cells. So numberOfRows should return the total count like rowsInSection = count of items + count of specifications in each items + count of list in each specifications for each item- Change your data source accordingly and make condition check so that you will display the item Name cell first then followed by the cell for Specification group name then display specification items inside each specification then show the next item name and so on.
我希望这种方法可以帮助你实现结果。
I hope this approach will help you achieve the result.
如果你能使用<$ c这将很容易$ c> tableView 在 tableViewCell
中,在许多应用程序中我使用过这种方法,我没有遇到任何Apple评论问题。如果您在 tableViewCell
中使用 tableView
,最好禁用滚动和跳出属性。
It will be easy if you could use tableView
inside the tableViewCell
, in many Applications I have used this approach and I haven't faced any Apple review problem. If you are using tableView
inside tableViewCell
it would be better to disable scrolling and bounces property.
这篇关于如何使用多级部分正确显示uitableview中的嵌套数组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!