1つのビューコントローラに複数のビューコントローラ( 'From'ビューコントローラ)を接続しましたItemCollectionVC
。 ItemCollectionVC
が提示されたとき、どのView Controllerがそれを提示したのか知りたい。
どうすればいいですか?ビューコントローラ 'から'どのビューコントローラがビューコントローラを提示したかを知る方法
:
@IBAction func selectOpponentItems(_ sender: UIButton) {
let VC = storyboard?.instantiateViewController(withIdentifier: "ItemCollectionVC") as! ItemCollectionVC
VC.preferredContentSize = CGSize(width: UIScreen.main.bounds.width/2, height: UIScreen.main.bounds.height/1.5)
VC.modalPresentationStyle = UIModalPresentationStyle.popover
VC.popoverPresentationController?.sourceView = sender
VC.popoverPresentationController?.sourceRect = sender.bounds
self.present(VC, animated: true, completion: nil)
}
ItemViewController:
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
編集:
私は財産をこのようにアクセスしようとしている:
のHowever, it crashes with error: unexpectedly found nil, I'm sure I set the title in storyboard
これは 'self.presentingViewController'メソッドで実現できます。 –
[アクセスモーダルビューコントローラの親]の複製の可能性があります(http://stackoverflow.com/questions/6735170/access-modal-view-controller-parent) – Larme