Create multilevel UITableview in swift without third party.

Save

Today, We will implement multilevel UITableview (like display categories list) in swift 5 without any third party. The items can be expanded and collapsed by tapping them. We create a basic design you can implement according to your requirement.

In this section, we implement tableview inside a UItableViewcell and the cell will be n level depth. Click here for more details about UITableview. And also we will manage the height of tableviewcell

Here we have used a JSON file for the data source and a specific structure so that we can easily manage it.

Getting Started

Swift version: 5
iOS version: 13
Xcode: 11.3

Step 1: Create a project from Xcode.

File ▸ New ▸ Project…. Choose the iOS ▸ Application ▸ Single View App template and create a new project.

Step 2: Add a UITableview inside the view controller and create Outlet. Here I will use a custom tableview class that helps to manage the height of the cell.

Step 3: Create a UItableViewCell for the tableView.

Step 4: Now parse the data which we will use in tableview. We have used some specific format of json shown in below.

Create a class to parse the data.

Now add the Delegate and Datasource of the tableview.

Step 5: Now create a model class which handles tableview delegate and datasource. We will use a common class for both tableview.

And the same model will use in UITableView. UITableViewCell code attached below.

Step 6: Now run the app in the simulator or a real device.

I hope this code will help you better to understand multilevel UITableview. If you feel any doubt or query please comment below.

Thank you.

. . .
Discuss on Helpdesk

Leave a Comment

Your email address will not be published. Required fields are marked*


8 comments

  • Farras
    Hi, I can’t find any JSON class, there is only JSONEncoder and JSONDecoder. Do you create ‘JSON’ class yourself?
  • beefTeriyaqie
    hi, when I try cell.tableView it says has no member tableView, do you happen to know why ?
    • Debabrata Roy (Moderator)
      I think you are accessing wrong class
  • Lau
    hi, when I try cell.tableView it says has no member tableView, do you happen to know why ?
    • Debabrata Roy (Moderator)
      I think you are accessing wrong class
  • Anwesh
    Hi Can you share the project guthub link?
    • Debabrata Roy (Moderator)
      Sorry, we do not upload code on GitHub.
  • css.php
    Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home