Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the view controller that is presenting and dismissing the modal, you should be calling the <code>dismissViewControllerAnimated:completion</code> method to dismiss the modal. The modal should not dismiss itself. You can use a completion block to execute whatever code you would like that will execute when the modal is finished dismissing. Example below.</p> <pre><code>[self dismissViewControllerAnimated:YES completion:^{ //this code here will execute when modal is done being dismissed [_tableView reloadData]; }]; </code></pre> <p>Of course don't forget to avoid capturing self strongly in the block.</p> <p>If you end up having the modal dismiss itself, you will need either a delegate method so the modal can communicate back to the presenting view controller, or a notification sent by the modal and captured by the presenting view controller, or you could implement <code>viewWillAppear:</code> in the presenting view controller. This method will fire everytime the view is about to appear. Which means the very first time as well as after a modal is dismissed and is about to show the view it was presenting over top of.</p> <p><strong>----------------------------------------------------------------------------------------</strong></p> <p>Below is an example of writing your own protocol and using it.</p> <p>MyModalViewController.h</p> <pre><code>@protocol MyModalViewControllerDelegate &lt;NSObject&gt; //if you don't need to send any data - (void)myModalDidFinishDismissing; //if you need to send data - (void)myModalDidFinishDismissingWithData:(YourType *)yourData @end @interface MyModalViewController : UIViewController @property (weak) id &lt;MyModalViewControllerDelegate&gt; delegate; //place the rest of your properties and public methods here @end </code></pre> <p>The where ever you want to in your MyModalViewController implementation file, call your delegate method of choice. You should first make sure your delegate actually responds to the selector though. MyModalViewController.m if ( [self.delegate respondsToSelector:@selector(myModalDidFinishDismissing)] ) [self.delegate myModalDidFinishDismissing];</p> <p>In your viewcontroller that is presenting the modal, you need to state in the header file that you conform to the protocol, you need to set the delegate of the modal as the viewcontroller, and make sure you actually implement the delegate method you intend on using.</p> <p>MyPresentingViewController.h</p> <pre><code>@interface MyPresentingViewController : UIViewController &lt;MyModalViewControllerDelegate&gt; </code></pre> <p>MyPresentingViewController.m</p> <pre><code>myModal.delegate = self; - (void)myModalDidFinishDismissing { //do something [tableView reloadData]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload