[英]How and where to initialize UITabBarControllerDelegate in Swift?
I have a UITabBarController
linked to 4 UIViewController
each embedded in a NavigationViewController
.我有一个
UITabBarController
链接到 4 个UIViewController
每个都嵌入在NavigationViewController
。
I need to check if when one of these view controllers is currently selected, and the user clicks the same tab bar item for the same view, it will trigger an unwind segue action.我需要检查当当前选择了这些视图控制器之一,并且用户单击同一个视图的同一个标签栏项目时,它是否会触发 unwind segue 操作。
So I think I need to add a UITabBarControllerDelegate
but when I tried to add it to the UITabBarController
class in the viewDidLoad()
method:所以我想我需要添加一个
UITabBarControllerDelegate
但是当我尝试将它添加到viewDidLoad()
方法中的UITabBarController
类时:
let tabBarDel: UITabBarControllerDelegate = UITabBarControllerDelegate()
I see the following error: ' UITabBarControllerDelegate
' cannot be constructed because it has no accessible initializers
.我看到以下错误:“
UITabBarControllerDelegate
”无法构造,因为它没有可访问的initializers
。
I extended the view controller class with UITabBarControllerDelegate.我使用 UITabBarControllerDelegate 扩展了视图控制器类。 In the viewDidLoad() method I used self.tabBarController?.delegate = self
在 viewDidLoad() 方法中,我使用了 self.tabBarController?.delegate = self
UITabBarController is a protocol, not a class. UITabBarController 是一个协议,而不是一个类。 You can't instantiate a protocol.
您无法实例化协议。 You need to create your own implementation of the protocol.
您需要创建自己的协议实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.