gpt4 book ai didi

ios - 访问 UITabBarController 的 subview Controller

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

我是 iOS 的新手,如何从 UITabBarController 访问 subview Controller ?目前,我有以下内容。

  1. 请求标签栏 Controller
  2. ActiveRequestsTableViewController
  3. 请求 View Controller

subview Controller 在 Storyboard中使用 Relationship Segue 连接。我想在 UITabBarController 的 subview 中设置一些属性。这是如何实现的。

Storyboard

storyboard_reference

最佳答案

您可以定义以下枚举来映射您的类:

enum TabType:Int {
case RequestTabBarController
case ActiveRequestsTableViewController
case RequestViewController
}

通过这种方式,您可以干净地访问您的viewControllers:

An array of the root view controllers displayed by the tab bar interface.

您可以直接从 UITabBarController 中获取,这样做:

private weak var tabVc:UITabBarController?
var niceObject:Whatever?
//...//
override public func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.tabVc = segue.destination as? UITabBarController

if let vc = self.tabVc?.viewControllers?[TabType.RequestTabBarController.rawValue] as? RequestTabBarController {
vc.doWhatEver(niceObject)
}
}

关于ios - 访问 UITabBarController 的 subview Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48515758/

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