mert mert -4 years ago 67
Objective-C Question

iOS Detecting Whether Tab is Changed

I have tabbed iOS application. I need to know which tab is active and detect when tab is changed. In storyboard I have a tab view controller, which changes the view when you click a tab fine. I created a class

and it is defined as follows:


@interface TabBarController : UITabBarController <UITabBarControllerDelegate>



#import "TabBarController.h"

@implementation TabBarController

// In the initialization section, set the delegate
- (id) init
self = [super init];
if (self)
self.delegate = self;
return self;

- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
NSLog(@"controller class: %@", NSStringFromClass([viewController class]));
NSLog(@"controller title: %@", viewController.title);


However, I couldn't detect tab changes with the code above. What do you think that the problem is?

I haven't linked my tab view to any outlets, but segues to other views. Is this the problem? Then, where should I link my outlet to?

Answer Source

Solution to this is the implementation viewDidLoad as follows:

- (void)viewDidLoad
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSLog(@"Tabs showed up!");
    self.delegate = self;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download