Instructions to create expand table view cell

Tram Ho

Hi, today’s article will guide you to create an expandable 1UITableviewcell, applicable in case of hiding / showing information. Based on the idea of ​​UIStackview, we will be able to design it simply, without creating many constraints.

Step 1: Create tableView, interface design

We imagine as follows: Initially the cell only has 2 labels, Family name and Age, the right corner is the SeeAll button, when pressed, it will show the information in a cell.

Step 2: Create Logic

In the management file, create a tabble view with 1 cell as designed, here is pull the outlet

Step 3: Create a Custion Cell file

And assign to the cell that created the UI before

At this point, we build the app to see if the view has been created successfully

Step 4: Create the hidden logic

In the custion cell file, we pull out let when we press the see all button and process it

Note: Closure expand is used to make call back, update cell when click see all / hide

Step 5: Update TableView (height)

On the main screen, we need to handle reloading tableview every time we update state

Above is an idea to implement dynamic UItableview cell, hope you will apply it successfully in your project. Thanks for reading the article


Share the news now

Source : Viblo