UITabBar无法更改所选索引

时间:2013-01-20 20:47:50

标签: ios delegates uitabbarcontroller uitabbar

我无法更改UITabBar的索引。我试图从UITabBarController子类更改它。这就是我正在尝试的:

[self.tabBarController setSelectedIndex:1];

这就是我的.h看起来像

#import <UIKit/UIKit.h>

@interface CustomTab : UITabBarController <UITabBarControllerDelegate>{
     IBOutlet CustomTab *bar;
}

@end

我正在尝试使用IBAction设置索引,正在调用该方法,但索引不会更改。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

因为你在打电话

[self.tabBarController setSelectedIndex:1];

来自CustomTab类本身。您需要将其替换为

[self setSelectedIndex:1];

答案 1 :(得分:0)

for swift

override func viewWillAppear(_ animated: Bool) {
    self .selectedIndex = 3 // desired index
}
相关问题