iOS tabBarController detect selected index in AppDelegate

AppDelegate.h *****

@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate,UITabBarDelegate>

AppDelegate.m *****

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex);
}

This method not work any idea ? I want to scroll top when click tab bar item Help please :)

Upvotes: 0

Views: 1032

Answers (1)

Aymen HARRATH
Aymen HARRATH

Reputation: 494

You just have to add this line in the viewDidLoad method of your first viewController :

self.tabBarController.delegate = ((AppDelegate *)[UIApplication sharedApplication].delegate);

Upvotes: 1

Related Questions