I have two view controllers (FirstViewController and SecondViewController) and a tab bar controller, and I use storyboards. In FirstViewController, a user can drag an image. Therefore, every time the user clicks on the second TabBarItem that the SecondViewController displays, I would like to check whether the user deleted the image or not every time she clicks the TabBarItem.
Therefore, I understand that this can be done using UITabBarDelegate and with its method -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item . But I am doing something wrong because the method is not being called, and I believe that this is because I cannot set the delegate correctly. Therefore, I want SecondViewController to be a delegate for TabBarController.
So in my SecondViewController.h I have the following
@interface SecondViewController : UIViewController<UITabBarDelegate>
And in SecondViewController.m I have
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { NSLog(@"%@", item); } - (void)viewDidLoad { [super viewDidLoad]; self.tabBarController.delegate = self; }
But nothing happens, and when setting up the delegate, I also get a compiler warning: Assigning an "id" from an incompatible type "SecondViewController * const __strong"
Please be careful with me, this is my first application, and for the first time I'm trying to use delegates.
source share