vipul
vipul

Reputation: 426

How can i give the values from one class to another in iphone?

Actually, i have some values calculated in my viewController.m of my project.And i use that final result in another class(uiview class) to draw that.But i can't understand how can i use the calculated values in my other class of same project in iphone.

Upvotes: 2

Views: 264

Answers (4)

Minakshi
Minakshi

Reputation: 1433

Go with following steps

  1. Declare the variables in delegate.h file

  2. write @property for the variable e.g.@property (nonatomic, retain) NSString *string;

  3. Synthesize in delegate.m

    @synthesize string;

  4. In the class(.h) where you want to use it

    //import yourDelegate.h YourDelegate *mainDelegate;

  5. In .m file

mainDelegate = [[UIApplication sharedApplication]delegate];

Upvotes: 1

Bradley
Bradley

Reputation: 617

Before you push into your new view you can pass variables accross.

E.g.

ViewController * viewcontroller = [ViewController alloc] init;
//pass your variables in here by setting the variables in the view your pushing into
viewcontroller.calculation = self.calculation;
//push into new view 
[self.navigationController pushViewController:viewcontroller animated:YES]; 
[viewcontroller release];

this allows you to set the variable calculation in your new class by making it equal your calculation variable on your original view, before pushing to the new view.

Upvotes: 0

ajay
ajay

Reputation: 3345

use setters and getters its essay for a beginner,or else go for property and synthesize.use this reference

Upvotes: 1

Klaasvaak
Klaasvaak

Reputation: 5644

When pushing a new view you can call methodes of that view. Don't know if that is what you are looking for.

Upvotes: 2

Related Questions