There may be several options for a solution.
- Use the
Singlton programming Singlton . Its purpose is to make a class object a single instance on the system.
Create a class with the properties you need for an example.
SingleTone.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface SingleTone : NSObject @property (strong, nonatomic) NSString * titleString; + (id)sharedManager; @end SingleTone.m #import "SingleTone.h" @implementation SingleTone @synthesize titleString; #pragma mark Singleton Methods + (id)sharedManager{ static SingleTone *sharedMyManager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedMyManager = [[self alloc] init]; }); return sharedMyManager; } @end
Thus, you create a class SingleTone After that, you set the parameters for the property you have registered in the right place.
In the case of a delegate, in the first controller method of the delegate we prescribe the setter stringArray is an array to fill the headers in the cells.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [[SingleTone sharedManager] setTitleString:[stringArray objectAtIndex:indexPath.row]]; } }
Each time you click on a new cell, the data will be overwritten.
To get a string in the new controller, you need to use the following method.
NSString * newString = [[SingleTone sharedManager] titleString];
And this line is already inserted where necessary;
- In advance to write in
property controller to which you pass, data.
In the new controller in the header you create the property
@property (strong, nonatomic) NSString * titleString
When moving from the first controller, before you push, transfer data.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ViewControllerSecondTable * detail = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerSecondTable"]; detail.titleString = [stringArray objectAtIndex:indexPath.row]; [self.navigationController pushViewController:detail animated:YES]; } }
It will remain only in the new controller to bring this property where you need.
NSString * newString = self.titleString
In general, the transfer options are many, for each case fits your own.