2017-09-04 6 views
0

ViewControllerの上に表示されるカスタムUIViewサブクラス(AccountInfoModal)がサブビューとして追加されています。 AccountInfoModalにはボタンがあり、別のViewControllerが表示されます。他のViewControllerを初期化することは問題ではありません。それを提示することです。カスタムUIView(xib-file)からView Controllerを表示

AccountInfoModalViewControllerではありません。.present(viewControllerToPresent...)は使用できません。

UIView内から別のViewControllerを表示する方法を教えてください。私はそれを把握することはできません。

編集:私はこの提案実装した :

let underlyingVC = UIApplication.shared.keyWindow?.rootViewController 
underlyingVC?.performSegue(withIdentifier: "SEGSignInViewController", sender: nil) 

をしかし、それは最後の行にクラッシュする(:...バンドル内NIBをロードできませんでした)。

答えて

0

このお試しください:AccountInfoModalクラス以上のプロトコルを作成AccountInfoModalファイルに

を:

protocol AccountInfoModalDelegate : class { 
func willPresentingViewController(){ 
} 

AccountInfoModalクラス内delegate変数定義:

:ボタンのアクション呼び出しの内側

weak var delegate? 

delegate?.willPresentingViewController() 
ViewControllerファイル内

この次の行を追加します。

extension ViewController : AccountInfoModalDelegate { 
    func willPresentingViewController(){ 
    let vc = AnotherVC() 
    self.present(vc, animated : true, completion : nil) 
    } 
} 

最後のステップは、あなたが

0

は、AccountInfoModalにcontainingViewControllerをプロパティを与えるAccountInfoModalビューを提示するために呼び出すところでAccountInfoModal delegate = selfのインスタンスを設定します。 AccountInfoModalビューをサブビューとしてインストールするときに設定します。それを使用して、他のView Controllerを表示します。

0

最も簡単な可能な方法 - ただ、現在のルートのUIViewControllerからのUIViewControllerその:

let vc = UIViewController() //Your UIViewController 
let rootVC = UIApplication.shared.keyWindow?.rootViewController //UIViewController from where you will present your UIViewController 
rootVC?.present(vc, animated: true, completion: nil) //Present method 
関連する問題