Reject two modal (tabular) view controller

I know that there are 3-5 similar questions here, but not the answers solve my problem.

I have a ViewController that opens a modal (table) view controller that opens another one. Both modal view managers are actually table view controllers. I try to fire them both from the second. I tried every accepted answer on a similar question, none of them worked for me.

I tried

[self dismissModalViewControllerAnimated:true] [self.parentViewController dismissModalViewControllerAnimated:true] [self.parentViewController.parentViewController dismissModalViewControllerAnimated:true] [self.presentingViewController dismissModalViewControllerAnimated:true] [self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:true] 

When I try to execute options 2, 3 and 5, nothing happens at all. When I use options 1 and 4, I see at first glance the animation of the modal view and the main view, and then everything returns to the second modal view (this time without animation).

I'm starting to think that this has something to do with the fact that I use tableViewControllers for modal views.

Btw, I reject modal views in the didSelectRowAtIndexPath file.

+4
source share
3 answers

Try the following: -

When you reject the SecondView value of the BOOL variable in the application delegation file and check that variable in your FirstView viewWillAppear method, whether SecondView was open and closed or not. If so, then [self dismissModalViewControllerAnimated:true]

+2
source

the typical behavior of the model view controller assumes that you are deflecting the modal view controller from the calling view controller, and not from yourself. not a hard rule, but good practice.

to accomplish this, create a protocol:

  @protocol MyModalViewControllerDelegate - (void)modalViewControllerDidFinish; @end 

and make both parentViewController and FirstModalViewController available for this protocol.

  @interface FirstModalViewController <MyModalViewControllerDelegate> 

then in FirstModalViewController.h and SecondModalViewController.h add:

  @property id<MyModalViewControllerDelegate> modalViewControllerDelegate 

in parentViewController and FirstModalViewController, just before calling presentModalViewController: ..., set the following:

  modalViewControllerAboutToAppear.modalViewControllerDelegate = self; [self presentModalViewController:modalViewControllerAboutToAppear animated:YES]; 

next, in SecondModalViewController, in the code where you specify that the item should be fired, call

  [self.modalViewControllerDelegate modalViewControllerDidFinish]; 

Now, in FirstModalViewController, do the following:

  - (void)modalViewControllerDidFinish:(MyModalViewController*)controller { [self dismissModalViewControllerAnimated:YES] [self.modalViewControllerDelegate modalViewControllerDidFinish]; } 

and finally, in the parent view controller, you can do:

  - (void)modalViewControllerDidFinish:(MyModalViewController*)controller { [self dismissModalViewControllerAnimated:YES] } 
+1
source

Since I do not use delegate files, I did the following:

In FirstView add a field

 BOOL mClose; 

In FirstView add a method

 - (void)close { mClose = YES; } 

In viewDidAppear add FirstView method

 if (mClose) { [self dismissModalViewControllerAnimated:YES]; } 

In FirstView method that opens the SecondView add

 [secondView closeWhenDone:self]; 

Add a field to SecondView

 FirstView *mParent; 

Add a method to SecondView

 - (void)closeWhenDone:(FirstView*)parent { mParent = parent; } 

In SecondView method that closes it adds

 [mParent close]; 
0
source

All Articles