I have 2 viewcontrollers which are named viewController and secondViewController. I want to get data and send it to secondViewController using delegates. Also i have a array in secondViewController, when each data came from VC1 it must store data like;
segue1,first data came -> arrayElements {firstData} segue2,second data came -> arrayElements {firstData, secondData}
But everytime the secondViewController comes into screen, it losts previous data(data from previous segues). Here my code;
FirstViewController.h
@protocol CustomDelegate <NSObject>
-(void)passData: (NSString*)data_in;
@end
@interface FirstViewController : UIViewController
@property (strong, nonatomic) NSString *myData;
@property (nonatomic, weak)id<CustomDelegate>delegate;
@end
FirstViewController.m (i copied only required part)
- (IBAction)sendButton:(UIButton *)sender {
SecondViewController *svc = [[SecondViewController alloc] init];
self.delegate = svc;
[self.delegate passData:self.myData];
}
SecondViewController.h
import things here..
@interface SecondViewController : UIViewController <CustomDelegate>
@property (strong, nonatomic) NSString *receivedData;
@property (strong, nonatomic) NSMutableArray* receivedDataArray;
@end
SecondViewController.m
//declerations, properties, lazy instantiation for array here
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
self.receviedDataLabel.text = self.receivedData;
}
-(void)passData:(NSString *)data_in{
self.receivedData = data_in;
[self.receivedDataArray addObject:data_in];
}
Here is the visual; http://i.hizliresim.com/ql8aJ3.png
As i said every time i click the show button to segue, i lost all my previous datas in the ViewController2.
I read previous questions like that, but most of them are about just passing one data. I'm very confused.
How can I stored these data using delegates without loss previous ones.