Search code examples
iosuitabbarcontrolleruitabbartabbar

Trouble using setSelectedIndex: method in UITabBarController


I'm using a TabBar View with its controller.

in .h: @interface TabsViewController : UITabBarController

in .m:

#import "TabsViewController.h"

@interface TabsViewController () < UITabBarDelegate, UITabBarControllerDelegate >

@end

@implementation TabsViewController

- (void)viewDidLoad {
    TabsViewController.setSelectedIndex:1; 
}

But last row give this error:

"Property 'setSelectedIndex' not found on object of type 'TabsViewController'"

Why? Thank you!


Solution

  • You are accessing selectedIndex property in wrong way.. I thinks you have created your own way to doing things in Objective-c. SelectedIndex in an instance Variable so you require same for setting/getting it.

    Rewrite your viewDidLoad as follows...

    - (void)viewDidLoad 
    {
        self.selectedIndex = 1; // or [self setSelectedIndex:1]
    }