gpt4 book ai didi

ios - 在项目选择上调用委托(delegate)方法

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

我在标签栏中有 3 个 View Controller 。我正在从 appdelegate 加载标签栏。现在我想在用户从标签栏更改 View Controller 时创建一个事件。为此,我在 appdelegate 中编写了委托(delegate)方法 didselectitem,并在我的 viewcontroller 中设置了委托(delegate)。但是委托(delegate)方法没有被调用。

在我的 View Controller 中,我正在写这个:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSLog(@"tabbar is %@",tabBar.selectedItem);

}

在viewdidload中:

MyAppDelegate.tabBar.delegate=self;

最佳答案

确保设置 UITabBarController 的委托(delegate)而不是标签栏本身。另外,确保实现正确的委托(delegate)方法:tabBarController:didSelectViewController:

更多信息在 UITabBarControllerDelegate documentation .

关于ios - 在项目选择上调用委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20738182/

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