title: UIViewcontroller not opening when button is pressed
body: <p>I have a problem occuring while running and testing my app.</p>
  
  <p>I've been using a tutorial offered by GeekyLemon.</p>
  
  <p>Part 1: <a href="http://www.geekylemon.com/xcode-in-app-purchase-part-1" rel="nofollow noreferrer">http://www.geekylemon.com/xcode-in-app-purchase-part-1</a></p>
  
  <p>Part 2: <a href="http://www.geekylemon.com/xcode-in-app-purchase-part-2" rel="nofollow noreferrer">http://www.geekylemon.com/xcode-in-app-purchase-part-2</a></p>
  
  <p>Part 3: <a href="http://www.geekylemon.com/xcode-in-app-purchase-part-3" rel="nofollow noreferrer">http://www.geekylemon.com/xcode-in-app-purchase-part-3</a></p>
  
  <p>Part 4: <a href="http://www.geekylemon.com/xcode-in-app-purchase-part-4" rel="nofollow noreferrer">http://www.geekylemon.com/xcode-in-app-purchase-part-4</a></p>
  
  <p>The tutorial teaches you how to use in-app purchases in your app and use it to create a "remove ads" feature for your app.</p>
  
  <p>After finishing the second part of the tutorial, I decided to run my code to see what I've accomplished so far. The view controller with my "Remove Ads" button shows up perfectly when I go to run my app. However, when I click on the button, it sends me to a screen that is pitch black instead of the view controller that I want it to go to.</p>
  
  <p>This is a screenshot of my two view controllers in my storyboard file. The view controller on the left has my "Removes ads" button. When it is clicked, I would like for it to go to the view controller on the right.</p>
  
  <p><img src="https://i.stack.imgur.com/CAthC.png" alt="enter image description here"></p>
  
  <p>Below are screenshots of my app in the simulator before and after I touch the "Remove Ads" button:</p>
  
  <p><img src="https://i.stack.imgur.com/F8hpd.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/l6wx2.png" alt="enter image description here"></p>
  
  <p>My SettingsViewController.h (Custom class for my first View controller in storyboard):</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;MessageUI/MessageUI.h&gt;
  #import &lt;StoreKit/StoreKit.h&gt;
  #import "PurchasedViewController.h"
  
  @interface SettingsViewController : UITableViewController &lt;   MFMailComposeViewControllerDelegate&gt;
  
  @property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
  
  @property (weak, nonatomic) IBOutlet UILabel *Label;
  - (IBAction)PurchaseItem:(id)sender;
  @property (strong, nonatomic) PurchasedViewController *purchaseController;
  -(void)Purchased;
  
  @end
  </code></pre>
  
  <p>My SettingsViewController.m:</p>
  
  <pre><code>#import "SettingsViewController.h"
  #import "SWRevealViewController.h"
  #define k_Save @"Saveitem"
  
  
  @interface SettingsViewController ()
  
  @property (nonatomic, strong) NSArray *menuItems;
  
  @end
  
  @implementation SettingsViewController
  
  @synthesize Label;
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
      // Custom initialization
  }
  return self;
  } 
  
  - (void)viewDidLoad
  {
  [super viewDidLoad];
  _sidebarButton.target = self.revealViewController;
  _sidebarButton.action = @selector(revealToggle:);
  _sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.7f];
  NSUserDefaults *saveapp = [NSUserDefaults standardUserDefaults];
  bool saved = [saveapp boolForKey:k_Save];
  if (!saved) {
      /// not save code here
  } else {
      ///saved code here
      Label.text = @"Item has been purchased.";
  
  // Add pan gesture to hide the sidebar
  [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
  // Do any additional setup after loading the view.
  }
  }
  
  
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  if(indexPath.row == 0 &amp;&amp; indexPath.section == 3){
      [[UIApplication sharedApplication] openURL:[NSURL  URLWithString:@"http://howtocrackthedbq.blogspot.com/"]];
  } else if(indexPath.row == 1 &amp;&amp; indexPath.section == 1){
           if ([MFMailComposeViewController canSendMail]) {
               MFMailComposeViewController *mailViewController =   [[MFMailComposeViewController alloc] init];
               mailViewController.mailComposeDelegate = self;
               [mailViewController setSubject:@"[How to crack the DBQ] Support request"];
               [mailViewController setToRecipients:[NSArray   arrayWithObject:@"moappsco@gmail.com"]];
               [self presentModalViewController:mailViewController animated:YES];
           }
            }
  
   }
  
  - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
  [self dismissModalViewControllerAnimated:YES];
  }
  
  - (void)didReceiveMemoryWarning
  {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  } 
  
  
  
  -(void)Purchased {
  Label.text = @"Item has been purchased.";
  NSUserDefaults *saveapp = [NSUserDefaults standardUserDefaults];
  [saveapp setBool:TRUE forKey:k_Save];
  [saveapp synchronize];
  }
  - (IBAction)PurchaseItem:(id)sender {
  
  _purchaseController = [[PurchasedViewController alloc] initWithNibName:nil bundle:nil];
  _purchaseController.productID = @"com.moappsco.crackingthedbq.dbq1";
  [[SKPaymentQueue defaultQueue] addTransactionObserver:_purchaseController];
  [self presentViewController:_purchaseController animated:YES completion:NULL];
  [_purchaseController getProductID:self];
  }
  @end
  </code></pre>
  
  <p>My PurchasedViewController.h (Custom Class for my other view controller shown on the right side of my storyboard):</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;StoreKit/StoreKit.h&gt;
  
  @interface PurchasedViewController :    UIViewController&lt;SKPaymentTransactionObserver,SKProductsRequestDelegate&gt; {
  }
  @property (strong, nonatomic) SKProduct *product;
  @property (strong, nonatomic) NSString *productID;
  @property (strong, nonatomic) IBOutlet UILabel *productTitle;
  @property (strong, nonatomic) IBOutlet UITextView *productDescription;
  @property (strong, nonatomic) IBOutlet UIButton *buyButton;
  
  - (IBAction)Restore:(id)sender;
  - (IBAction)BuyProduct:(id)sender;
  - (IBAction)GoBack:(id)sender;
  
  -(void)getProductID:(UIViewController *)viewController;
  
  @end
  </code></pre>
  
  <p>My PurchasedViewController.m:</p>
  
  <pre><code>#import "PurchasedViewController.h"
  #import "SettingsViewController.h"
  
  @interface PurchasedViewController ()
  
  @property (strong, nonatomic) SettingsViewController *homeViewController;
  
  @end
  
  @implementation PurchasedViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
      // Custom initialization
  }
  return self;
  }
  
  - (void)viewDidLoad
  {
  [super viewDidLoad];
  _buyButton.enabled = NO;
  // Do any additional setup after loading the view.
  }
  
  - (void)didReceiveMemoryWarning
  {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
  
  - (IBAction)Restore:(id)sender {
  [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
  }
  
  - (IBAction)BuyProduct:(id)sender {
  SKPayment *payment = [SKPayment paymentWithProduct:_product];
  [[SKPaymentQueue defaultQueue] addPayment:payment];
  }
  
  - (IBAction)GoBack:(id)sender {
  [self dismissViewControllerAnimated:YES completion:NULL];
  
  }
  -(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
  [self UnlockPurchase];
  }
  
  -(void)getProductID:(SettingsViewController *)viewController;{
  _homeViewController = viewController;
  
  if([SKPaymentQueue canMakePayments]){
      SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:  [NSSet setWithObject:self.productID]];
      request.delegate = self;
      [request start];
  } else
      _productDescription.text = @"Please enable in-app purchases in your settings.";
  }
  
  
  #pragma mark _
  #pragma mark SKProductsRequestDelegate
  
  -(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
  NSArray *products = response.products;
  if (products.count != 0) {
      _product = products[0];
      _buyButton.enabled = YES;
      _productTitle.text = _product.localizedTitle;
      _productDescription.text = _product.localizedDescription;
  } else {
      _productTitle.text = @"Product not found.";
  }
  products = response.invalidProductIdentifiers;
  
  for(SKProduct *product in products) {
      NSLog(@"Product not found: %@", product);
  }
  
  
  }
  -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions    {
  for (SKPaymentTransaction *transaction in transactions) {
      switch (transaction.transactionState) {
          case SKPaymentTransactionStatePurchased:[self UnlockPurchase];
              [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
              break;
          case SKPaymentTransactionStateFailed:NSLog(@"Transaction Failed");
              [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
          default:
              break;
  
      }
  }
  }
  
  -(void)UnlockPurchase {
  _buyButton.enabled = NO;
  [_buyButton setTitle:@"Purchased" forState:UIControlStateDisabled];
  [_homeViewController Purchased];
  }
  @end
  </code></pre>
  
  <p>If needed, you can download my xcode project on Github: <a href="https://github.com/MoAppsCo/iOS-Apps/tree/master/How%20to%20crack%20the%20DBQ" rel="nofollow noreferrer">https://github.com/MoAppsCo/iOS-Apps/tree/master/How%20to%20crack%20the%20DBQ</a></p>