2011-11-08 47 views

回答

0

您可以通过设置文本字段的值在委托变量:

appDelegate.textValueVariable = textfieldA.text ;

现在,您可以通过从ClassB的访问委托变量: (写在ClassB的的viewDidLoad或下面的代码viewWillAppear

textfieldB.text = appDelegate.textValueVariable ;

0

将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; 
} 
1

简单:

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; 
} 
相关问题