Read now

Create multilevel UITableview in swift without third party.

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.

. . .

Comment (1)

Add Your Comment

  • Dai Software
    Thank you for sharing such a nice and informative Blog.
    online food ordering app development
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close