Pass Data Back To The Previous View Controller Using Callback

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.

Callback:

-> 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:-

Conclusion

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.

 

 

 

 

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

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