title: Dismissing a UIViewController from a UIActionSheet Class
body: <p>I created a <code>UIActionSheet</code> Class that will allow me to log out from anywhere within my app. the issue that I am having is once I hit logout button it should also dismiss the current <code>viewController</code> and go back to the login <code>viewController</code>. Below is a snippet of my code.</p>
  
  <pre><code>NSObject.h file 
  
  @interface constants : NSObject&lt;UIActionSheetDelegate&gt;{
  
      UIActionSheet *msg;
  
  }
  
  -(void)presentMyActionSheet;
  @property (nonatomic, strong) UIView *viewForActionSheet;
  
  
  NSObject.m file
  
  -(void)presentMyActionSheet{
  
  msg = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Log Out" otherButtonTitles:nil, nil];
  
  [msg showInView:self.viewForActionSheet];
  
  }
  // actionsheet delegate protocol item
  - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
  
      NSLog(@"button index = %ld", (long)buttonIndex);
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
      if(buttonIndex == 0){
                  [defaults setObject:nil forKey:@"acctInfo"];
                  [defaults setBool:NO forKey:@"isLoggedOn"];
  
                  NSLog(@"You logged out");
  </code></pre>
  
  <p>This is what I tried.</p>
  
  <pre><code>   viewController *controller = [[viewController alloc]init];
     [controller.navigationController popViewControllerAnimated:NO];  
     [controller dismissViewControllerAnimated:NO completion:nil];
  </code></pre>
  
  <p>it does not work.</p>
  
  <pre><code>            }else{
  
                  NSLog(@"You canceled logout");
              }
  
  }
  
   viewController.h file
  
  @interface viewController : UIViewController&lt;UIActionSheetDelegate&gt;
  
  @property(nonatomic, retain)constants *obj;
  
  
  viewController.m file
  
  @synthesize obj;
  
  {
      self.obj = [[constants alloc] init];
      self.obj.viewForActionSheet = self.view;
      [self.obj presentMyActionSheet];
  
      if([defaults boolForKey:@"isLoggedOn"]){
  
  If I try it from here it crashes.
       //   [self.navigationController popViewControllerAnimated:NO];
       //   [self dismissViewControllerAnimated:NO completion:nil];
  
      }
  }
  </code></pre>
  
  <p>Any suggestions as to why it is not working?</p>
  
  <p>Thanks</p>