2017-03-09 4 views
0

ViewControllerを却下し、別のViewControllerを提示したいと思います。 FirstViewControllerViewControllerを終了し、別のViewControlloer-IOS-Swiftを提示してください。

@IBAction func loadFirstVCClicked(_ sender: UIButton) 
{ 
    self.present(FirstViewController.loadVC() 
} 

static func loadVC() -> SecondViewController 
{ 
    let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController 
    return vc 
} 

@IBAction func exitClicked(_ sender: UIButton) 
{ 
    self.dismiss(animated: true, completion: { 
     //present MainVC - second VC should work as an interstitial ad 
    }) 
} 

そして、私はこのエラーを取得する:

はSecondViewController
static func load() -> FirstViewController 
{ 
    let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstViewController") as! FirstViewController 
    return vc 
} 
@IBAction func exitClicked(_ sender: UIButton) 
{ 
    self.dismiss(animated: true, completion: { 
     self.present(SecondViewController.loadVC() 
    }) 
} 

MainVC:ここに私のコードがある「ビューではありませんFirstViewControllerにSecondViewControllerをウィンドウの階層に! "

これは表示されません。あなたからの任意の提案

FirstViewController-> SecondViewController-> MainVC

なりますので、基本的に私はSecondViewControllerがSecondViewControllerとMainVC didLoad

のdissmisal基本スキーム間のインタースティシャル広告の一種になりたいです本当に感謝します。ありがとうございました!

+0

@IBAction func loadFirstVCClicked(_ sender: UIButton) { let firstViewController = self.storyboard?.instantiateViewController(withIdentifier: "FirstViewController") as! FirstViewController self.present(firstViewController) } @IBAction func loadMainVCClicked(_ sender: UIButton) { let mainViewController = self.storyboard?.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController self.present(firstViewController) } class MainViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // there you can present your interstitial viewcontroller } } class InterstitialViewController: UIViewController { // when user press close or after a time limit dismiss } 

プロトコル(代理人)のサンプル

// give the name you want protocol LiveProtocol: class { func onFirstViewControllerDismissed() } 

そして、あなたのライブのViewControllerのViewController広告を表示します既に閉じられているFirstViewControllerから提示する。あなたはMainVCから発表するべきです。 – orxelm

+0

私はMainVCによって実装され、それを閉じるときにSecondVCによって呼び出されるデリゲートを使用します。その後、MainVCはSecondVCを終了し、FirstVCを提示します。 –

答えて

0

ビューコントローラーを作成するために静的関数を使用しないでください。間質最初のオープンmainviewcontrollerとonViewDidAppearを表示する適切な方法は、あなたがしようとしているfirstviewcontroller

class LiveViewController: UIViewController, LiveProtocol { 

    ... 

    internal func onFirstViewControllerDismissed() { 

     // present your interstitial 

    } 

} 
+0

こんにちは、ありがとうございます。私は、FirstVCが表示されていないときにのみインタースティシャルを表示したいと思います。 –

+0

あなたは、 FirstVCが却下し、デリゲートを介してトリガーし、インタースティシャル – abdullahselek

+0

が表示される可能性はありますか?私はこのようにパターンを委任するためにiosに新しいです –

関連する問題