swift - 标签栏; childView 继续

标签 swift

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

相关文章:

ios - AVplayer 无法播放 iPhone 画廊中的视频

iOS 等待服务器数据改变 UITableView 外观

swift - 保留循环内的值

带有 NSUIntegerMax 的 Objective-C 兼容 Swift 枚举

arrays - 快速保存图像数组

swift - 使用 Core Data 属性创建 UI 本地通知

ios - Realm 通知 block 返回未修改的值

ios - 我如何引用以编程方式添加文本字段以从 Swift 内部获取数据?

json - Swift 2.0 如何解析 JSON?

swift - 如何使用 Alamofire 将 CURL 请求转换为 Swift?