我是iphone的新手,我正在使用UITextfield输入值并在其中显示,但我无法将textfield值传递给另一个类。如何将文本字段值传递给iphone中的另一个类文本字段?
classA
textfieldA.text=3
如何将textfieldA值传递给textfieldB?
classB
textfieldB.text=
我是iphone的新手,我正在使用UITextfield输入值并在其中显示,但我无法将textfield值传递给另一个类。如何将文本字段值传递给iphone中的另一个类文本字段?
classA
textfieldA.text=3
如何将textfieldA值传递给textfieldB?
classB
textfieldB.text=
您可以通过设置文本字段的值在委托变量:
appDelegate.textValueVariable = textfieldA.text ;
现在,您可以通过从ClassB的访问委托变量: (写在ClassB的的viewDidLoad
或下面的代码viewWillAppear
)
textfieldB.text = appDelegate.textValueVariable ;
将TextfieldA值转换为变量,然后将该类推送到另一个类,然后使用该类发送您的值,并在另一个类中创建相同类型的变量,并将该变量的值分配给类似于此的文本字段 - -
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];
}
现在Class B{
//创建一个同名变量SETY传递价值
int y;
textfieldB.text=y;
}
简单:
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 {
[email protected]"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;
}
在委托变量中设置该值并从ClassB访问该变量。 – Maulik