Reputation: 1
I'm new to iphone, I'm using a UITextfield to enter the values and display in it, but i cannot pass the textfield value to another class.
classA
textfieldA.text=3
how to pass the textfieldA value to textfieldB ?
classB
textfieldB.text=
Upvotes: 0
Views: 896
Reputation: 23510
Easy :
ClassA.h
@interface ClassA : NSObject {
UITextField* textfield;
}
@property(nonatomic, retain) UITextField* textfield;
ClassB.h
@ClassA;
@interface ClassB : NSObject {
ClassA* refClassA;
UITextField* textfield;
}
@property(nonatomic, retain)ClassA* refClassA; // you can also use assign instead of retain if you masterize the concept
@property(nonatomic, retain)UITextField* textfield;
ClassA.m
@synthesize textfield;
- (void) somefunction {
self.textfield.text=@"3";
}
// and somewhere when creating ClassB
yourClassBObject.refClassA = self;
ClassB.m
#import "ClassA.h"
@synthesize refClassA;
@synthesize textfield;
- (void) somefunction {
self.textfield.text = self.refClassA.textfield.text;
}
Upvotes: 1
Reputation: 19418
You can set the value of text field in delegate variable by :
appDelegate.textValueVariable = textfieldA.text ;
Now You can access the delegate variable from ClassB by :
(write the below code in ClassB's viewDidLoad
or viewWillAppear
)
textfieldB.text = appDelegate.textValueVariable ;
Upvotes: 0
Reputation: 187
Take the TextfieldA value into a variable and then push the class to the another class and then with the class send your value and in the another class create a same type of variable and assign that value of the variable to the textfield similar like this--
Class A {
textfieldA.text=3;
int x;
anotherViewController *subControllr=[[anotherViewController alloc] initWithNibName:@"anotherViewController" bundle:nil];
[subControllr setY:x];
UINavigationController *controller =[[UINavigationController alloc] initWithRootViewController:subControllr];
controller.navigationBar.barStyle = UIBarStyleBlackOpaque ;
[subControllr setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[[self navigationController] presentModalViewController:controller animated:YES];
[subControllr release];
[controller release];
}
Now Class B{
//create the same name variable as setY for passing the value
int y;
textfieldB.text=y;
}
Upvotes: 0