title: ViewWillAppear Getting Called twice
body: <p>I am writing an application on iOS 7 using storyboards.</p>
  
  <p>I have a navigation controller as my root view controller and I embed a view controller within it.</p>
  
  <p>When the application loads, viewDidLoad gets called once and viewWillAppear gets called once. This is correct (also I check for data &amp; update the view in view will appear).</p>
  
  <p>However, in my view controller, i have a button which allows the user to share the information via SMS/text using the 'MFMessageComposeViewController' controller.</p>
  
  <p>So the code here is</p>
  
  <pre><code>MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
  
  if([MFMessageComposeViewController canSendText])
  
  { 
      controller.body = [NSString stringWithFormat:@"Some Text Here"];
  
      controller.messageComposeDelegate = self;
  
      [self presentViewController:controller animated:YES completion:nil];
  }
  </code></pre>
  
  <p>and the delegate function is</p>
  
  <pre><code>- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
  {
   switch (result) {
        case MessageComposeResultCancelled:
             NSLog(@"Cancelled");
             break;
        case MessageComposeResultSent:
             NSLog(@"Message Sent");
             break;
        default:
             break;
   }
  
  [self dismissViewControllerAnimated:YES completion:nil];
  //[controller dismissViewControllerAnimated:YES completion:nil]; //tried this as well but same result
  
  }
  </code></pre>
  
  <p>However, when i called dismissViewControllerAnimated.. the viewDidAppear method is being called twice. Do you know why this is happening as this is checking data twice and there by adding things twice to my view instead of only once?</p>
  
  <p>Thanks,
  Varun</p>
  
  <p>1st - Stacktrace of ViewDidAppear is</p>
  
  <pre><code>0   Sweep                               0x0010a8f1 -[GoogleMapsViewController viewDidAppear:] + 56
  1   UIKit                               0x2fd3673f &lt;redacted&gt; + 410
  2   UIKit                               0x2fde6657 &lt;redacted&gt; + 182
  3   UIKit                               0x2fd3673f &lt;redacted&gt; + 410
  4   UIKit                               0x2fd36bcd &lt;redacted&gt; + 264
  5   Sweep                               0x000e9909 -[RESideMenu viewDidAppear:] + 88
  6   UIKit                               0x2fd3673f &lt;redacted&gt; + 410
  7   UIKit                               0x2fd36bcd &lt;redacted&gt; + 264
  8   UIKit                               0x2fe3321b &lt;redacted&gt; + 1682
  9   UIKit                               0x2fe32ab7 &lt;redacted&gt; + 170
  10  UIKit                               0x2fe329e3 &lt;redacted&gt; + 74
  11  UIKit                               0x2fe328c9 &lt;redacted&gt; + 288
  12  UIKit                               0x2fe323d9 &lt;redacted&gt; + 944
  13  UIKit                               0x2fd53ab7 &lt;redacted&gt; + 178
  14  UIKit                               0x2fd539cf &lt;redacted&gt; + 66
  15  QuartzCore                          0x2f9a9413 &lt;redacted&gt; + 234
  16  libdispatch.dylib                   0x37dd90af &lt;redacted&gt; + 22
  17  libdispatch.dylib                   0x37ddb9a9 _dispatch_main_queue_callback_4CF + 268
  18  CoreFoundation                      0x2d5625b1 &lt;redacted&gt; + 8
  19  CoreFoundation                      0x2d560e7d &lt;redacted&gt; + 1308
  20  CoreFoundation                      0x2d4cb471 CFRunLoopRunSpecific + 524
  21  CoreFoundation                      0x2d4cb253 CFRunLoopRunInMode + 106
  22  GraphicsServices                    0x322052eb GSEventRunModal + 138
  23  UIKit                               0x2fd80845 UIApplicationMain + 1136
  24  Sweep                               0x00098299 main + 116
  25  libdyld.dylib                       0x37dedab7 &lt;redacted&gt; + 2
  </code></pre>
  
  <p>)</p>
  
  <p>2nd - Stacktrace of ViewDidAppear is</p>
  
  <pre><code>0   Sweep                               0x0010a8f1 -[GoogleMapsViewController viewDidAppear:] + 56
  1   UIKit                               0x2fd3673f &lt;redacted&gt; + 410
  2   UIKit                               0x2fde6657 &lt;redacted&gt; + 182
  3   UIKit                               0x2fd3673f &lt;redacted&gt; + 410
  4   CoreFoundation                      0x2d4e0803 &lt;redacted&gt; + 50
  5   CoreFoundation                      0x2d4da21d &lt;redacted&gt; + 220
  6   UIKit                               0x2fd3687b &lt;redacted&gt; + 726
  7   UIKit                               0x2fd36bcd &lt;redacted&gt; + 264
  8   UIKit                               0x2fe3321b &lt;redacted&gt; + 1682
  9   UIKit                               0x2fe32ab7 &lt;redacted&gt; + 170
  10  UIKit                               0x2fe329e3 &lt;redacted&gt; + 74
  11  UIKit                               0x2fe328c9 &lt;redacted&gt; + 288
  12  UIKit                               0x2fe323d9 &lt;redacted&gt; + 944
  13  UIKit                               0x2fd53ab7 &lt;redacted&gt; + 178
  14  UIKit                               0x2fd539cf &lt;redacted&gt; + 66
  15  QuartzCore                          0x2f9a9413 &lt;redacted&gt; + 234
  16  libdispatch.dylib                   0x37dd90af &lt;redacted&gt; + 22
  17  libdispatch.dylib                   0x37ddb9a9 _dispatch_main_queue_callback_4CF + 268
  18  CoreFoundation                      0x2d5625b1 &lt;redacted&gt; + 8
  19  CoreFoundation                      0x2d560e7d &lt;redacted&gt; + 1308
  20  CoreFoundation                      0x2d4cb471 CFRunLoopRunSpecific + 524
  21  CoreFoundation                      0x2d4cb253 CFRunLoopRunInMode + 106
  22  GraphicsServices                    0x322052eb GSEventRunModal + 138
  23  UIKit                               0x2fd80845 UIApplicationMain + 1136
  24  Sweep                               0x00098299 main + 116
  25  libdyld.dylib                       0x37dedab7 &lt;redacted&gt; + 2
  </code></pre>
  
  <p>)</p>