简体   繁体   English

无法从一个视图控制器获取值到另一个

[英]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 做两件事

  1. property and synthesize of your nameValue in your root view controller 根视图控制器中nameName属性和属性的合成
  2. modify your code as below 如下修改您的代码

-(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.

相关问题 无法将值从一个视图控制器传递到情节提要上的另一个 - Not able to pass value from one view controller to another on storyboard 我无法将值从一个视图控制器传递给另一个视图控制器 - i am not able to pass value from one view controller to another view controller 无法使用 UITabBarController 将一个视图 controller 发送到另一个视图 controller - Not able to sent one view controller to another view controller using UITabBarController 将字符串值从一个视图控制器传递给另一个 - Pass a string value from one view controller to another 如何从一个ViewController在另一个View Controller中为NSString设置值 - How to set value for NSString in another view controller from one viewcontroller 如何将字符串值从一个视图控制器传递到另一个视图控制器 - how to pass a string value from one view controller to another view controller 将对象从一个View Controller添加到另一个View Controller上的阵列 - Add Objects From One View Controller To An Array On Another View Controller 如何从一个视图控制器弹出到另一个视图控制器 - How to pop from one view controller to another view controller 如何从一个视图控制器导航到另一视图控制器? - How to navigate from one view controller to another view controller? 从另一个视图控制器调用One View控制器的方法 - Calling a method of One View controller from Another View Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM