0

I have an issue the dismissing view controller to the tabbed view controller. I will explain my flow.

  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];
    //shareview.finalvideourl=videoURL;
    shareview.videooutputstring=videoPath;
    
  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.

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Why don't you store that information in AppDelegate and set it in "shareViewController" and access it in your 1st Tab or wherever desired. – Dipen Panchasara Aug 05 '16 at 04:37
  • @Dipen can please elaborate it – Satheeshkumar Naidu Aug 05 '16 at 04:42
  • 1
    In App delegate.h write @property (nonatomic, retain) NSString *databaseName or what ever property u need. initiate the same in .m The controller you need save the details, there import AppDelegate.h and in viewDidLoad write objAppDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate]; you can now access the AppDelegate string – gurmandeep Aug 05 '16 at 04:46
  • As @gurmandeep explained you need to use set & get value using AppDelegate instance. – Dipen Panchasara Aug 05 '16 at 04:49
  • @gurmandeep I am using the array not string,one more thing is when i first open tabbed view controller it should print 15 array objects in the collection view .Next i am passing data from share view controller to the tabbed view controller now i can to print 16 array objects,if i repeat same process now 17 objects,post you answer please it will usefull to others also – Satheeshkumar Naidu Aug 05 '16 at 04:53

3 Answers3

0

I'm not sure why you are creating new storyboards using your main storyboard. All you have to do is presentViewController from one the viewcontroller you want to return from with the id of a segue from that viewcontroller back to the root of your tabbed view controller. In your storyboard, ctrl+drag from a button (or whatever is triggering the segue) and drag it to the root of the tab view controller. Select the segue and in the attributes editor give it an id. then in the viewcontroller call presentViewcontroller with the id and it should work fine.

Gabe Spound
  • 568
  • 5
  • 28
  • I that case My root controller is not tabbed view controller i Have one view controller before that. – Satheeshkumar Naidu Aug 05 '16 at 04:35
  • -(void) receivedArray:(NSNotification*)notification { NSMutableArray* userInfo = notification.object; UIImage *image = [userInfo firstObject]; if ([userInfo count]>0) { [app.array1 insertObject:[userInfo firstObject] atIndex:0]; [self.collection reloadData]; NSLog(@"%@",app.array1); } – Satheeshkumar Naidu Aug 05 '16 at 09:12
0

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

In

- (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];

then

[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.

gurmandeep
  • 1,227
  • 1
  • 14
  • 30
  • I have only one array.Initially it will have 15 objects defaults I am adding it 15 objects _imagearray=[@[@"bootimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo",@"prinimages",@"resplendent",@"tnb4",@"Tomato-plant",@"Vole",@"waterimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo"]mutableCopy]; in .m view did load ,I am getting the 1 object I am adding in to the array like this [_imagearray insertObject:[userInfo firstObject] atIndex:0]; – Satheeshkumar Naidu Aug 05 '16 at 06:43
  • Ok shall is change the whole app delegate to this array? I can do that for you – gurmandeep Aug 05 '16 at 06:46
  • please bro,did you under the what I am trying to explain you brother if not i will explain you again – Satheeshkumar Naidu Aug 05 '16 at 06:48
  • Please check and let me know – gurmandeep Aug 05 '16 at 06:57
  • it is working but two problems 1.it is printing one extra object 2.if i add other image previous added image is same images but count is increasing i.e first viewdid load 15objects,next add one object it should come 16 but it is 17,if i add other image count is 18 but 16,17,18 is same as 18th image – Satheeshkumar Naidu Aug 05 '16 at 07:23
  • Are you sure at what index or when to add new object? Then remove all object after index 14 and add the new one. That will make the count constant – gurmandeep Aug 05 '16 at 08:59
  • no problem with the count only thing is when i add second time old add image and new add image is same it should be different that is the problem,i will add one time gallery image next time captured image next time video first frame image – Satheeshkumar Naidu Aug 05 '16 at 09:05
  • Can you share the code snippet of adding. The array wont check for the new or old image – gurmandeep Aug 05 '16 at 09:08
  • below mentioned is the code to add new object for the present array – Satheeshkumar Naidu Aug 05 '16 at 09:16
  • -(void) receivedArray:(NSNotification*)notification { NSMutableArray* userInfo = notification.object; UIImage *image = [userInfo firstObject]; if ([userInfo count]>0) { [app.array1 insertObject:[userInfo firstObject] atIndex:0]; [self.collection reloadData]; NSLog(@"%@",app.array1); } – Satheeshkumar Naidu Aug 05 '16 at 09:16
  • Are you sure the notification is being called once? – gurmandeep Aug 05 '16 at 09:19
  • no it is calling twice,it is adding twice,i dont know y diz is happening – Satheeshkumar Naidu Aug 05 '16 at 09:25
  • Hi bro did find the solution – Satheeshkumar Naidu Aug 05 '16 at 10:37
  • @naidu, share the whole code man so that i can check what thing is wrong – gurmandeep Aug 05 '16 at 10:40
  • i think i have cocoa pods, lets give it a try – gurmandeep Aug 05 '16 at 10:44
  • Hi good morning Bro I have sent you can you please check it out – Satheeshkumar Naidu Aug 06 '16 at 04:46
  • check this link for delegate methods, at bottom i have added a simple delegate call http://stackoverflow.com/questions/38386535/using-a-delegate-to-pass-information-from-button-to-highlight-cell/38388362#38388362 – gurmandeep Aug 08 '16 at 04:38
  • HI good morning,Happy friendship day ,@protocol childDelegate where should i declare this wether in the shareviewcontroller r tabbed view controller – Satheeshkumar Naidu Aug 08 '16 at 04:54
  • I am not getting it brother can you please add it in answer and it will be use full for the future reference – Satheeshkumar Naidu Aug 08 '16 at 05:11
0

In the shareViewcontroller.h write the add the following method

@protocol childDelegate <NSObject>
 -(void) sendImage:(UIImage *)img
@end

and the property

@property (assign) id <childDelegate> cDelegate;

once you have done that on the controller where you have the method

-(void) receivedArray:(NSNotification*)notification

add the method

-(void) sendImage:(UIImage *)img
{
 // Add image to app.array1 here.
}

In the share view controller where you are sending the image to the last controller call this method

[self.cDelegate sendImage:"your image comes here"];

Still if you face as issue, then refer to How do I set up a simple delegate to communicate between two view controllers?

Let me know if you still face an issue.

Community
  • 1
  • 1
gurmandeep
  • 1,227
  • 1
  • 14
  • 30
  • bro I am Taking the Image in to the array and I ma passing that array bro – Satheeshkumar Naidu Aug 08 '16 at 05:41
  • I have gallery,camera,video every time I will take any one output from one of it and I am adding that output to the array now i want pass that array. – Satheeshkumar Naidu Aug 08 '16 at 05:45
  • instead of (UIImage *) pass (NSArray *) or (NSMutableArray *) – gurmandeep Aug 08 '16 at 05:50
  • I am getting issue -[PhotoViewController sendarray:]: unrecognized selector sent to instance 0x17877800,iadd protocol like this @protocol shareViewControllerDelegate -(void) sendarray:(NSMutableArray *)protoarray; -(void) sendtitlearray:(NSMutableArray *)protitlearray; @end[self presentViewController: nc animated:YES completion:^{ [self.adelegate sendarray:_selectedimgarray]; [self.adelegate sendtitlearray:_newtile]; ]}; – Satheeshkumar Naidu Aug 08 '16 at 06:21
  • in tabbed first view controller -(void) sendarray:(NSMutableArray *)protoarray{ UIImage *image = [protoarray firstObject]; [app.array1 insertObject:[protoarray firstObject] atIndex:0]; _collection.delegate=self; _collection.dataSource=self; } -(void) sendtitlearray:(NSMutableArray *)protitlearray{ [app.tarray1 insertObject:[protitlearray firstObject] atIndex:0]; _collection.delegate=self; _collection.dataSource=self; } if any miskakes tell me – Satheeshkumar Naidu Aug 08 '16 at 06:22
  • The method call will be shareViewControllerDelegate sendArray – gurmandeep Aug 08 '16 at 06:39
  • I am not getting you – Satheeshkumar Naidu Aug 08 '16 at 06:43
  • Please join https://chat.stackoverflow.com/rooms/120389/view-controller-to-tabbed-view-controller – gurmandeep Aug 08 '16 at 06:49