2

I have Button Click event which present a AssetScreenPopupViewController,in AssetScreenPopupViewController I am dynamically adding a NSNumber to NSMutableArray(emailClkArray).

When i dismiss the viewcontroller, i am retreiving this emailClkArray in my BrowseProgrammingTools. but i am always getting blank arrays.

My code for presenting modalviewcontroller is

- (void)imageViewTapped:(UITapGestureRecognizer *)gr {
    AssetScreenPopupViewController * assetController =
    [[AssetScreenPopupViewController alloc]init];
    assetController.AssetContentArray = tableData_one;
    assetController.myStringValue = gridPopUpController.assetName.text;
    [self.navigationController presentViewController:assetController animated:NO
       completion:nil];
    NSLog(@"Asset ARRAY %@",assetController.emailClkArray);
    [self.navigationController.delegate self];
}

The ModalViewController Class method in which i am adding value to array is as follows

 - (IBAction)emailClkBtn:(id)sender {
          [self.emailClkArray replaceObjectAtIndex:k withObject:[NSNumber numberWithInt:1]];
          [self.emailBtnOutlet setBackgroundImage:newImage1 forState:UIControlStateNormal];
          NSLog(@"WMA  dhbc%@",self.emailClkArray);
       }

And when I am dismissing the view Controller i have assigned emailClkArray to
ParentViewController MutableArray like this

- (IBAction)dismissClk:(id)sender {
     BrowseProgrammingTools *browsePrgTools = [[BrowseProgrammingTools alloc]init];
     browsePrgTools.emailClkArray = self.emailClkArray;
     [self dismissViewControllerAnimated:NO completion:Nil];
}

When I am print this array in viewDidAppear method of BrowseProgrammingTools like this

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:YES];
    self.emailClkArray = [[NSMutableArray alloc]init];
    NSLog(@"DNW%@",self.emailClkArray);
}

I am getting Blank Array like this

DNW(
 )

please help me how to get the value?

santhu
  • 4,796
  • 1
  • 21
  • 29
nikk3008
  • 79
  • 1
  • 7

2 Answers2

1

You are misunderstanding the flow of control.

When you call presentViewController:animated:completion:, the call returns immediately. Your next line after that executes before the view controller has even been displayed to the screen.

You should set up your AssetScreenPopupViewController to have a delegate property. Define a protocol that the AssetScreenPopupViewController will use to communicate with the view controller that calls it when the user is finished making their selection.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
1

Your problem is here:

- (IBAction)dismissClk:(id)sender {
     BrowseProgrammingTools *browsePrgTools = [[BrowseProgrammingTools alloc]init];
     browsePrgTools.emailClkArray = self.emailClkArray;
     [self dismissViewControllerAnimated:NO completion:Nil];
}

You're instantiating a new view controller, passing it an array, then..... well, then nothing. That view controller disappears when you dismiss the VC that owns it-- which you do in the very next line of code. The line BrowseProgrammingTools *browsePrgTools = [[BrowseProgrammingTools alloc]init]; does NOT grab the presenting VC, it creates a new instance of it.

You will probably want to create some delegate methods in your presented VC (look up @protocol), then set the delegate right after you set the navigation controller's delegate. Then, don't call [self dismissViewControllerAnimated:NO completion:Nil];, call it in whatever method the delegate implements.

AMayes
  • 1,767
  • 1
  • 16
  • 29