2011-11-08 71 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; 
} 
相關問題