How to Transfer Data between views in Xamarin iOS.

Xamarin.iOS
img_xamarin

We have create a tutorial about how to go to one view to another but what about passing data between this views. In this tutorial we are going to extend our last tutorial , so if you didn’t look at it please refer it. We just pass segue push to transfer views in it.

To transfer data between views we need to override PrepareForSegue method. This method on the initial view controller and handling the data ourselves. When the segue is triggered – for example, with a button press – the application will call this method, providing an opportunity to prepare the new view controller beforeany navigation occurs.

First we are goin to add a label on second view controller and add it name as “lbl_data”. Create a UIViewController instance give it name as TransferView and assign it to second view controller. Also declare a string variable and give it name as data.

Now for root view controller create a UIViewController instance and name it as NavigationSegue and assign it to the root view controller.We are going to remane the button text as “Click here”.

Now in NavigationSegue write:

this PrepareForSegue method will pass data between our root view to second view by string variable we declared in file TransferView.

Now in TransferView write:

And that’s all. Try to build and run the project and you will see string that you write on root view controller in second view like:

9e

10a

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">