[英]Not able to fetch value from one view controller to another
Well I have two view controllers.. 好吧,我有两个视图控制器。
In controller1 I have a textField 在controller1中,我有一个textField
Now My problem is whenever I enter anything in that textField..I want to use that value in view controller 2... 现在我的问题是,每当我在该textField中输入任何内容时,我都想在视图控制器2中使用该值。
but the value is coming null in viewController 2...I don't know what is going wrong?? 但是该值在viewController 2中为null ...我不知道怎么了?
I know I am making silly mistake but what is that?? 我知道我犯了愚蠢的错误,但这是什么? can anyone help me here? 有人能帮我一下吗?
This is the code of my viewController 2 's .m file 这是我的viewController 2的.m文件的代码
- (void) save_Clicked:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
textName=txtCoffeeName.text;
rootViewController.nameValue=textName;
NSLog(@"%@",textName);
}
well here I want to use the value of nameValue in rootViewController...which is showing me null..:( rootViewController is the object of RootViewController which is declared in .h file and textName is the string which is declared too 好在这里我想在rootViewController中使用nameValue的值...这向我显示了null ..:
请设置synthesize属性为rootViewController.nameValue,textName的保留。您必须使用self.rootViewController.nameValue,self.textName ...我认为它将解决您的问题。
Do 2 things 做两件事
-(void) save_Clicked:(id)sender { -(void)save_Clicked:(id)sender {
textName=txtCoffeeName.text; textName = txtCoffeeName.text;
rootViewController.nameValue=textName; rootViewController.nameValue = textName;
NSLog(@"%@",textName); NSLog(@“%@”,textName);
[self.navigationController dismissModalViewControllerAnimated:YES]; [self.navigationController dismissModalViewControllerAnimated:YES];
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.