Pass Data Back To The Previous View Controller Using Callback

Updated 6 June 2019


So let’s assume you have two view controllers: FirstViewController and SecondViewController. The user navigates from FirstViewController to the SecondViewController. SecondViewController will process some business logic and the result of that business logic will need to be sent back to the FirstViewContoller when the user navigates back.

Here I’m using the call back for sending data back from SecondViewController to FirstViewController.


-> Callbacks are very important when we are doing any asynchronous task in the background and need to change the UI based on the response.

First Step->

First, we make the call back in SecondViewController.

here this callback returns void means nothing.

Second Step->

We will Navigate from FirstViewController to the SecondViewController. here we are using below code to push from FirstViewController to the SecondViewController.

Third Step->

Now we will call callBack from SecondViewController when the user press on the back button.

Fourth Step->

In this step, the callback block will execute and print the data.

Complete Code:-


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







. . .

Leave a Comment

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


  • Timur
    • jitendra kumar (Moderator)
  • Halu
  • Start a Project

      Message Sent!

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

      Back to Home