i made 2 views and i want to send text of label on main view to sub view to an want to print it there on another label's text value.... how to pass that text
If class A handle your view1 and Class B handle view2 then define a interfaces in class B to accept new label to your one of the UI element then call that interface from class A.
Look into the Singleton pattern.
Then you could do something like:
//view1
#import "SingletonClass.h"
...
[SingletonClass sharedInstance].savedText = @"blah";
and
//view2
#import "SingletonClass.h"
...
lbl.text = [SingletonClass sharedInstance].savedText;
I wouldn't use a singleton pattern or any other 'global variable'. This will make your view controllers very tightly coupled and restricts reusability. I would just create a instance variable in the second view controller and set this in the main one before presenting the view.
The second view controller then sets the label.text to the instance variable in (for example) viewDidLoad.
This way, the second view controller doesn't depend on any 'globals' or includes and will be more reusable.
//SecondViewController.h
@interface SecondViewController : UIViewController {
NSString *theLabel;
}
@property(nonatomic, copy) NSString *theLabel; //Synthesize in implementation
@end
Then in the main view controller:
//Create instance of secondViewController
instanceOfSecondViewController.theLabel = @"Nut";
//Present the second view here