我有一个带有textFieldA的类A和带有textFieldB的类B.
我想将textFieldA和textFieldB的值访问到C类,并希望在标签中显示。
如果我使用合成,我如何访问这些值或任何其他值? 那么这是我的班级 -
(IBAction)buttonPress:(id)sender
{ NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:field1.text forKey:@"field1Key"];
[defaults setObject:field2.text forKey:@"field2Key" ];
[defaults setObject:field3.text forKey:@"field3Key"];
[defaults synchronize];
ConfirmController *conf=[[ConfirmController alloc]initWithNibName:nil bundle:nil];
// corfim=[[ConfirmController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:conf animated:YES ];
[conf release];
}
This is classB:-- -
(void)viewWillAppear:(BOOL)animated
{
label.text=massage; currancyLabel.text=massage1;
[super viewWillAppear:animated];
outputRate.text=[[NSUserDefaults standardUserDefaults]objectForKey:@"outputRateKey"];
float x= [amount.text floatValue]*[massage floatValue];
outputRate.text=[NSString stringWithFormat:@"%.2f", x];
}
我想在C类中显示这些类textFields ConfirmController类是classC,formController是classA,currancyController是classB
答案 0 :(得分:0)
我不明白你对“作曲”的意思。无论如何,如果你的班级“C”你初始化两个实例:
A *a;
B *b;
然后您可以使用以下方式访问这两个文本值:
NSString *textA = a.textFieldA.text; NSString *textB = b.textFieldB.text;
答案 1 :(得分:0)
步骤1:为A类和B类创建一个对象,例如objA和ObjB
步骤2:分别为A类和B类创建属性textFieldA和textFieldB
步骤3:在班级C中创建一个标签,让我们说标签C
步骤4:现在访问文本字段的值
NSString* msgA = objA.textFieldA.text
NSString* msgB = objB.textFieldB.text
Step5:
labelC.text = [msgA stringByAppendingString:msgB];