I am not able to get text field value in to next t

2019-09-02 04:50发布

问题:

I have a TabBarController with two tabs; first is InputViewController and second one is TableviewController.

Input view controller has two text fields when I enter the text, after that I want to receive that text filed value in to TableviewController (in the next tab). It does not receive the value.

回答1:

Try to use this concept..... Declare two variables in Second tab that is Tableviewcotroller.. For exa..

NSString *strname;
NSString *straddr;

@property and @synthesize both...

Now, in your *InputViewCotroller*tab, create and initialize object of TableViewcotroller, using this object, access these varibles. Like, you want to get values of textfields.

Tableviewcotroller *objTable = ........
objTable.strname = self.textName.text;
objTable.straddr = self.txtAddr.text;

Implement this concept in your project...Hope this helps you...:)



回答2:

What ever value you have in input view controller like

  NSString*text1=textbox1.text;
  NSString*text2=textbox2.tex;

In the method where you are moving to next view you should pass the value to the table view controller like this

DetailViewController*tblViewController=[[DetailViewController alloc]init];
NSString*textValue1=text1;

tblViewController.textValue1=textValue;

[self.navigationController pushViewController:tblViewController];

you should alos have textValue NSString in tableView controller also to assign value