Handling Text field In Table View

Updated 30 November 2021

Save

Handling text field in table View is a way to manage text fields and prevent the text fields entered data while reloading the table.

When we use text fields in table view then text fields data will be removed when you reload the table.

So handle this issue we will use a model to save the text fields entered data.

And then pass the same model data in table view text fields.

And we are using textFieldDidEndEditing delegate to fetch the text filed data and save it in the model.

Handling text field in table View we will use the below steps.

1-> Create table view in controller

First, we will take a table view in the controller.

2-> Create cell for table view

Now we will create a cell for the table view. and the cell will contain two text fields.

3-> Create the model for saving text fields data

We have created the TextFieldModel model and in the model have two variable.

4-> Add the table view delegate

In the cell for a row, we have given a tag to identify the text fields in text fields delegates.

5-> Add text field delegate for fetch text field data

Here we are using did end editing delegate to save data in the model.

We used cell to identify the edited text fields with the index path of the cell.

-> Final code

This is the final view controller code for handling the text fields in the table view.

Now run the project and enter the data in text fields then reload the table with scrolling.

Then you will see your data will never loss and your code will work smoothly.

And thanks for reading this blog, for more blogs please click here.

So pls follow the above step and And if you have any issues or suggestions you can leave your message in the comment section I will try to solve this.

author
. . .

Leave a Comment

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


2 comments

  • Sagar
    • jitendra kumar (Moderator)
  • Start a Project


      Message Sent!

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

      Back to Home