Swift通过UITabBarController访问viewController的函数
我有一个需要更新的tableView。正如另一个问题在这里解释:Swift updating UITableView with new dataSwift通过UITabBarController访问viewController的函数
无论如何。正确的答案最终与我原来的问题完全无关,并且我被提出了关于如何调用我需要调用它的特定viewController函数的另一个问题。
这是我的控制器设置。
NavigationController
ContainerViewController. (2 childViewControllers)
menuTabBarController (this is a UITabBarController)
SuggestionsViewController (This is the viewController I need to run a function from)
...
SideBarViewController
具有UITableView
的的viewController是suggestionsViewController
。
我需要运行该功能的viewController是SideBarViewController
。
我想调用的函数被调用loadSuggestions()
我的第一次尝试,当然是刚运行:
SuggestionsViewController().loadSuggestions()
但是在我的其他问题进行说明。这创建了它的一个新实例,而不是在viewController上运行loadSuggestions()
,我想更新我的UITableView
帮助推断UITableView未更新的问题的用户(rdelmar)指出我在/正确/方向,我得到了以下代码工作:
(menuTabBarController.viewControllers as! [UIViewController])[0]
但是,我目前的问题是,我不能访问loadSuggestions()
从
所以。简而言之。我需要使用功能loadSuggestions()
更新我的UITableView
,当我点击我的滑出菜单上的按钮时。
这怎么办?
如果(menuTabBarController.viewControllers as! [UIViewController])[0]
是正确的视图控制器,那么您可以强制转换as SuggestionsViewController
,只要它不是私有方法,您就可以调用该方法。
由于您得到的数组是UIViewController
,并且UIViewController
没有loadSuggestions
方法,所以不能使用该方法调用该方法。
完美的工作!非常感谢。在这里呆了好几天。大量的帮助。尽管如此,仍然不能接受3分钟。谢谢!!!!! –
很高兴帮助:) –