Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

ios - how to display nested array data inside uitableview properly with Multiple level of Sections

I have the following json data

{
   "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

enter image description here

I can achieve this via uitableview inside uitableviewcell but as per Apple recommendation Apple does not recommend table views to be added as subviews of other scrollable objects

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you don't wish to use tableView inside tableViewCell, you could possible go by the following approach.

  • 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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...