Satheeshkumar Naidu Satheeshkumar Naidu - 1 year ago 94
Objective-C Question

How to come back from view controller to tabbed view controller

I have an issue the dismissing view controller to the tabbed view controller.I will explain my flow please help me out

1.view controller to tabbed view controller(push)
2.I have 5 tabs in the tabbed view controller in the 3 tabbed i have an camera view from their i am presenting the view controller and passing some parameters by using this code

UIStoryboard *storybord=[UIStoryboard storyboardWithName:@"Main" bundle:nil];

shareViewController *shareview=[storybord instantiateViewControllerWithIdentifier:@"share"];
[self presentViewController:shareview animated:YES completion:nil];

3.from the share view controller I want send the data back to the 1st tab for this I am using the below code

UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
TabedfirstViewController *Tabedfirst=[story instantiateViewControllerWithIdentifier:@"id"];

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:Tabedfirst];

[self presentViewController: nc animated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShareArray" object:_selectedimgarray];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SharetitleArray" object:_newtile];
[[NSNotificationCenter defaultCenter] postNotificationName:@"sharevideooutputstring" object:_videooutputstring];

When I do this very thing working good I am sending the data from share view to the tabbed view and I am printing it.

but the problem is when i send the second time data from share viewcontroller to the tabbed view controller first data is deleting and the second passed data is replacing the first.i.e i have the 15 objects in an array,from share view controller I am passing array to the tabbed view controller now the array count is 16 and i am printing it, now again I am passing one more object from the share view to tabbed view the array count must increase to 17 but it 16 only.

please help out to solve this problem.if you dont understand this get back to me please

Answer Source

In the App delegate add/make properties of your arrays like

 @property (nonatomic, retain) NSMutableArray *array1;

In AppDelegate.m initiate all your properties

After that in the controller where you are storing the values add instance of AppDelegate as


- (void)viewDidLoad
  [super viewDidLoad];
   objAppDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
  objAppDelegate.array1= _imagearray=[@[@"bootimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo",@"prini‌​mages",@"resplendent",@"tnb4",@"Tomato-plant",@"Vole",@"waterimages",@"fall-photo‌​graphy-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo"]mutable‌​Copy];


[objAppDelegate.array1 insertObject:[userInfo firstObject] atIndex:0];

The values are maintained and can be used anywhere in the whole project. If your number of objects keeps on increasing then you NSMutableDictionary and add as much key/value pairs as you like.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download