gpt4 book ai didi

ios - 如何知道哪个 View Controller 呈现了一个 View Controller

转载 作者:搜寻专家 更新时间:2023-11-01 06:37:16 25 4
gpt4 key购买 nike

我有几个 View Controller (“来自” View Controller )连接到一个 View Controller ItemCollectionVC
ItemCollectionVC 出现时,我想知道哪个 View Controller 呈现它。

如何做到这一点?

“来自” 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)
}

项目 View Controller :

override func viewDidLoad() {
super.viewDidLoad()
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}

编辑:

我正在尝试以这种方式访问​​该属性:

 switch self.presentingViewController!.title! {
// Error
case "CounterBuildVC":
dataSourceItems = counterBuildItems
case "FreeBuildVC":
dataSourceItems = freeBuildItems
case "KrakenViewController":
dataSourceItems = captureKrakenItems
default:
break
}

However, it crashes with error: unexpectedly found nil, I'm sure I set the title in storyboard

最佳答案

presentingViewController UIViewController 的属性就是你要找的东西

关于ios - 如何知道哪个 View Controller 呈现了一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40039928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com