【发布时间】:2020-05-04 22:12:20
【问题描述】:
我有一个标签栏控制器。当用户单击选项卡栏按钮之一时,我需要更新目标视图控制器中的 UIPageViewController 中的值。
我正在尝试使用委托通知 UIPageViewController 点击了哪个标签栏按钮:
protocol PlanTypeDelegate {
func setIntro(thisFlow planType: UITabBarItem)
}
class NewTabBarController: UITabBarController {
var planTypeDelegate : PlanTypeDelegate?
override func viewDidLoad() {
super.viewDidLoad()
// create and handle tab bar button actions
}
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
planTypeDelegate?.setIntro(thisFlow: item)
}
在我的 UIPageController 中,我有以下内容:
class IntroPageController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
guard let tabbar = self.parent as? NewTabBarController() else { return }
tabbar.delegate = self
}
}
extension IntroPageController : PlanTypeDelegate {
func setIntro(thisFlow planType: UITabBarItem) {
print("this item:\(planType)")
}
}
我不熟悉在 VC 之间传递数据,所以我不知道如何处理这种情况。
【问题讨论】:
标签: ios swift delegates protocols