[英]UITabBarController add new UIViewController above storyboard ones (Swift)
I have a storyboard file with a UITabBarController
connected to 4 view controllers, and I want to add number 5 programmatically. 我有一个Storyboard文件,其中的
UITabBarController
连接到4个视图控制器,我想以编程方式添加5。 In Objective-C I did as below: 在Objective-C中,我这样做如下:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSArray *tabs = self.viewControllers;
//set tab controllers
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:(@"Settings_Storyboard_iPad") bundle:nil];
AddFolderViewController *vc = [storyboard instantiateInitialViewController];
self.viewControllers = [NSArray arrayWithObjects:[tabs objectAtIndex:0], [tabs objectAtIndex:1], [tabs objectAtIndex:2], [tabs objectAtIndex:3], vc, nil];
}
In a UITabBarController
subclass. 在
UITabBarController
子类中。 However in Swift I don't seem to be able to do it. 但是在Swift中,我似乎无法做到这一点。 It doesn't let me either access the indices of tabs, or append the
controller
. 它不允许我访问选项卡的索引,也不能追加
controller
。
override func viewDidLoad() {
super.viewDidLoad()
var viewControllers: [UIViewController] = self.viewControllers as! [UIViewController];
let storyboard : UIStoryboard = UIStoryboard(name:"Main", bundle: nil)
let thirdVC : ThirdViewController = storyboard.instantiateViewControllerWithIdentifier("ThirdVC") as! ThirdViewController
let icon1 = UITabBarItem(title: "Third", image:UIImage(named: "image.png"), selectedImage:UIImage(named: "otherImage.png"))
thirdVC.tabBarItem = icon1
viewControllers.append(thirdVC)
self.viewControllers = viewControllers
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.