我期中有一个HomeViewController 是UIViewController 是点击第一个UITabBarItem触发的页面 然后我想在这个页面中写代理UITabBarDelegate 也就是我想用-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)Item 这个方法 但是一旦写了这一句 self.tabBarController.tabBar.delegate = self;就报错 难道不是这样获取代理吗
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的HomeViewController是继承自UITabBarController吗?
如果是的话不需要再手动设置self为代理,同理UITableViewController
self.tabBarController.tabBar.delegate = self
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)Item
以上应该写在UITabBarController中,而不是写在UIViewController中。