2016-10-11 7 views
0

View Controllerをポップオーバーとして表示しようとしていますが、フルスクリーンで表示されているときにiPhone上で正常に動作しますが、iPadではクラッシュします。iPadでPopover View Controllerがクラッシュする

@IBAction func selectOpponentItems(_ sender: UIButton) { 

    let VC = storyboard?.instantiateViewController(withIdentifier: "ItemSelectionVC") as! ItemSelectionVC 
    // Error here 
    VC.delegate = self 
    VC.preferredContentSize = CGSize(width: UIScreen.main.bounds.width/2, height: UIScreen.main.bounds.height/2) 
    VC.modalPresentationStyle = UIModalPresentationStyle.popover 
    self.present(VC, animated: true, completion: nil) 
} 

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle { 
    return .none 
} 

エラーメッセージは言う:

は 'Overpower.ItemSelectionVC' (0x10005ad40)にタイプ 'の値のUIViewController'(0x1b1e33f60)にキャストできませんでした。

+0

例外メッセージとは何ですか?どのラインで発生するのですか? – Paulw11

+0

@ Paulw11 plz編集 –

+0

あなたのストーリーボードをチェックするのは、ItemSelectionVCではなく単にUIViewControllerであるため、強制ダウンキャストは失敗します。 – Paulw11

答えて

1

TonyMkenuの答え@以下は、私がselectOpponentItemsに、コードのこれらの2行を追加し、それは魔法のように働いた:

VC.popoverPresentationController?.sourceView = sender 
VC.popoverPresentationController?.sourceRect = sender.bounds 
関連する問題