gpt4 book ai didi

swift - 标签栏; childView 继续

转载 作者:行者123 更新时间:2023-11-30 13:20:18 25 4
gpt4 key购买 nike

我正在尝试制作一个具有带 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.

您可以通过转到对象库并搜索“对象”来完成一个简洁的实现:

enter image description here

将其拖动到选项卡栏 View Controller 并通过 ctrl + 拖动设置其委托(delegate)。

选择它:

enter image description here

并在检查器中设置自定义类:

enter image description here

当您右键单击该对象时,您应该看到:

enter image description here

这是您的 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/

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