我正在尝试制作一个具有带 2 个 View 的选项卡栏 View 的应用程序。第一个包含一个 tableView。使用第二个,您可以将元素添加到 tableView 中。现在我希望能够在 View 之间进行通信
在标签栏 Controller 中切换标签时是否有segues?我怎样才能拦截它们?如果没有,两个 View 之间是否有其他通信的可能性?
最佳答案
您可以使用 UITabBarControllerDelegate 拦截 View Controller 之间的实际切换。使用方法tabBarController:didSelectViewController: :
Tells the delegate that the user selected an item in the tab bar.
您可以通过转到对象库并搜索“对象”来完成一个简洁的实现:
将其拖动到选项卡栏 View Controller 并通过 ctrl + 拖动设置其委托(delegate)。
选择它:
并在检查器中设置自定义类:
当您右键单击该对象时,您应该看到:
这是您的 CustomClass 的示例:
class CustomClass : NSObject, UITabBarControllerDelegate
{
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController)
{
}
}
而 viewController 参数是:
The view controller that the user selected. In iOS v3.0 and later, this could be the same view controller that was already selected.
这意味着您需要检查它是哪个 VC。
关于swift - 标签栏; childView 继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37828659/