gpt4 book ai didi

ios - UITabBarControllerDelegate 的 shouldSelect 方法从未被调用

转载 作者:行者123 更新时间:2023-11-28 12:11:36 25 4
gpt4 key购买 nike

我正在使用 Swift 4 和 XCode 9。我正在尝试以编程方式控制我的 UITabBarController 中的导航。根据Apple's documentation ,我需要实现 UITabBarControllerDelegate 协议(protocol)。但是,我实现的方法从未被调用:

import UIKit

class TabBarController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()

tabBarController?.delegate = self
}

func tabBarController(_ tabBarController: UITabBarController,
shouldSelect viewController: UIViewController) -> Bool {
print("Should go here...")
return true
}
}

知道我做错了什么吗?

最佳答案

您的问题是您设置了错误的委托(delegate)。将 viewDidLoad 更新为:

override func viewDidLoad() {
super.viewDidLoad()

self.delegate = self // or just "delegate = self"
}

想法是您希望此选项卡 Controller 成为它自己的委托(delegate)。

关于ios - UITabBarControllerDelegate 的 shouldSelect 方法从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48332473/

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