简体   繁体   中英

How to pass values from one page to other page and display values in the page's textlabel of cell in iPhone?

I have an application in which when I click on the table item a new page opens, which allows me to enter details in textfield and textview, and clicking on the submit button it should navigate to the previous page which is a tableview and populate the the textlabel of the cell of the table view with the value which are entered in the textfield and textview.

How is this possible? How could I populate the tableview cell with the values entered in the textfield and textview?

Everything depends on how the data are stored in your TableView. For example if you have a plist file you must re-write this file when you submit new value.

After that, on :

- (void)viewWillAppear:(BOOL)animated {}

You must reload plist file and invok [self.tableView reloadData];

However there is an other method. If you have just few values you can use NSUserDefault class Reference to store data in your app.

You Need to use following delegate function:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

objInf.nameLable =[NSString stringWithFormat:@"Hello %@ Have a Good Day :)",[listData objectAtIndex:indexPath.row]];
NSLog(@"Next View Value =%@",[listData objectAtIndex:indexPath.row]);
NSLog(@"Next View Value =%@",objInf.nameLable);
[self presentModalViewController:objInf animated:YES];
}

As objInf is second class's object and nameLable is NSString which you can set as text of label of your second class where u want to display the data..

By using property you can do this. string properties of textfield strings on input page then simply by making object of that page you can access these property.

remember you need singletone object if you make new object then it reintialise the properties.

so use this for making object of that input class.

YourClass *obj= (YourClass *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-2];

this gives object from navigation stack.

That can be achieved by 2 ways.

One is, You can have 2 NSString property in another ViewController. 1 Method to assign data in that. like

  • @property (nonatomic,retain) NSString *textfieldValue; and Synthesize it.
  • @property (nonatomic,retain) NSString *textviewValue; and Synthesize it.
-(void) contentToDisplay: (NSString *)pTxtFieldValue txtViewValue(NSString*)pTxtViewValue{
    self.textfieldValue = pTxtFieldValue;
    self.textviewValue = pTxtViewValue;
}

While switching to another ViewController by submitting use its object to assign text like

  • [objViewController contentToDisplay:@"textfieldvalue" txtViewValue:@"textviewValue"];

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM