I am attempting creation and use of a UITabBar in IOS. My code generates a UITabBar but when I click on a tab it crashes with error -
- (main thread) "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)"
Here is the code, which is called in the view controller's viewDidLoad()
let v1 : UIView = UIView(frame:self.view.frame);
let v2 : UIView = UIView(frame:self.view.frame);
v1.backgroundColor = UIColor.redColor();
v2.backgroundColor = UIColor.blueColor();
let vc1 : UIViewController = UIViewController();
let vc2 : UIViewController = UIViewController();
vc1.view = v1;
vc2.view = v2;
vc1.title = "View 1";
vc2.title = "View 2";
let nav1 : UINavigationController = UINavigationController(rootViewController: vc1);
let nav2 : UINavigationController = UINavigationController(rootViewController: vc2);
nav1.delegate = self;
nav2.delegate = self;
let tabsArr : [UINavigationController] = [nav1, nav2];
let main_tab : UITabBarController = UITabBarController();
main_tab.viewControllers = tabsArr;
main_tab.delegate = self;
self.view.addSubview(main_tab.view);
Here is the view from the code above
Question
How to get this to work, 100% programmatically? When I click on a tab I would like to respond with a tab change!
Thanks :)