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!

有帮助吗?

解决方案

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]
}

其他提示

You need to get a reference of your UITabBar object from the UITabBarController and the method you will want to call is setSelectedItem:(UITabBarItem *)

UITabBar *bottomTabBar = self.tabBar;
[bottomTabBar setSelectedItem:[bottomTabBar.items objectAtIndex:1]];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top