How to pass a value from one UIViewController to another UIViewController?

This post deals with passing of an integer value from one

UIViewController class to another UIViewController class…

Suppose there are two UIViewController classes

FirstViewController

SecondViewController

 

Now we have to pass an integer value from FirstViewController to SecondViewController

We can use @property to pass values from one class to another but the problem is that the property can be a object only

So we will have to use NSNumber object to store int value as an object and later use it as a property

 

In the SecondViewController.h file

write

NSNumber *value;

@property(nonatomic,retain) NSNumber *value;

In the SecondViewController.m file

@synthesize value; after @implementation

In the FirstViewController.m file

SecondViewController *second=[[SecondViewController alloc] initWithNibName:@”SecondViewController” bundle:nil];
testing.value=[NSNumber numberWithInt:9];

Don’t forget to include SecondViewController.h file in the FirstViewController.h file.

Now in SecondViewController.h file access the value of property by

 

[self.value intValue]

2 thoughts on “How to pass a value from one UIViewController to another UIViewController?

  1. Pingback: variable value hasn't been changed when transmisson between Views - iPhone Dev SDK Forum

  2. What a great web log. I spend hours on the net reading blogs, about tons of various subjects. I have to first of all give praise to whoever created your theme and second of all to you for writing what i can only describe as an fabulous article. I honestly believe there is a skill to writing articles that only very few posses and honestly you got it. The combining of demonstrative and upper-class content is by all odds super rare with the astronomic amount of blogs on the cyberspace.

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> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>