2013-12-18 101 views
4

我已經按照教程將In App Purchase添加到我的應用中。有2次:使用故事板的當前視圖控制器

  1. 按鈕「購買物品」
  2. 窗口彈出,允許用戶選擇產品

我添加的代碼完全沒問題,但在本教程中,他們使用XIB文件,但我正在使用Storyboard。我對「購買物品」按鈕的代碼看起來是這樣的:

- (IBAction)PurchaseItem:(id)sender { 

    _purchaseController = [[PurchasedViewController alloc] initWithNibName:Nil bundle:nil]; 

    _purchaseController.productID = @"com.myapp"; 

    [self presentViewController:_purchaseController animated:YES completion:NULL]; 

    [_purchaseController getProductID:self]; 

} 

我的問題是,當點擊該按鈕時,會出現黑屏,但我想PurchasedViewController顯示

我是否需要改變一些東西?

編輯:

使用作爲附加編輯的代碼,但得到的錯誤:

- (IBAction)PurchaseItem:(id)sender { 

     PurchasedViewController *purchaseContr = (PurchasedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"menu"]; 
     //menu is only an example 
     purchaseContr.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
     [self presentViewController:purchaseContr animated:YES completion:nil]; 

    } 

enter image description here

+0

出於好奇,什麼是'[PurchasedViewController getProductID:]'做? – Macondo2Seattle

+0

它從第一個視圖控制器獲得產品ID – Omar

+1

行'_purchaseController.productID = @「com.myapp」;'然後做什麼? – Macondo2Seattle

回答

19

有了記事板,你應該給一個標識符喜歡的圖片:在您的viewController 水龍頭in'身份檢查員'

enter image description here

在這個例子中自定義類應該是:PurchasedViewController

,這是代碼:

- (IBAction)PurchaseItem:(id)sender { 
    PurchasedViewController *purchaseContr = (PurchasedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"menu"]; 
    //menu is only an example 
    purchaseContr.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    [self presentViewController:purchaseContr animated:YES completion:nil]; 
} 
+0

謝謝,我在哪裏添加代碼在我的代碼中? – Omar

+0

@Omar檢查我編輯的答案 – Ilario

+0

我在這一行上得到一個錯誤'_purchaseController * purchaseContr =(_purchaseController *)[self.storyboard instantiateViewControllerWithIdentifier:@「menu」];'在發送消息開始時缺少'[''表達 – Omar

0

試試這個

_purchaseController = [[PurchasedViewController alloc] init]; 

_purchaseController.productID = @"com.myapp";   
/* 1. Add the new VC as a child VC */ 
[self addChildViewController:_purchaseController]; 

/* 2. Add new view to source view */ 
[self.view addSubview:_purchaseController.view]; 

/* 3. Inform 'didMoveToParentViewController' to newly added view controller */ 
[_purchaseController didMoveToParentViewController:self]; 

[_purchaseController getProductID:self]; 
+0

謝謝,但你的代碼沒有做任何事情的按鈕 – Omar

+0

沒有得到你所說的話你能解釋更多「代碼doent做任何事按鈕「的意思是 –

+1

他說你的代碼不適合他 –

相關問題