Load views using a tab element!

You can make a presentation using a tab bar item. let me explain the question clearly to you. I created a presentation based application. Two passes are added, let's say first and second. the first view contains a button that takes us to the second view. The second view also contains a button that leads us to the third view. I added a tab bar to the third view and added four tab bar elements to it. Now I want to associate the elements of the tab bar with the views. Say 4th, 5th and 6th.

1st view (Buton) → 2nd view (button) → third view (contains a tab bar and 4 tab positions). But all objects have empty representations. When I select a tab bar item, I have to upload the .xib files that I created. How to associate a tab bar item with a view controller so that I can load views. Else, are there any other options for loading views with tab bar items?

+3
source share
1 answer

If you mean how you load the views into the controller of the tab bar, then do something like this:

UITabBarController *tabView = [[UITabBarController alloc] init];
UIViewController *view4 = [[UIViewController alloc] init];
UITabBarItem *view4TabBarItem = [[UITabBarItem alloc] initWithTitle:@"4" image:[UIImage imageNamed:@"icon4.png"] tag:nil];
view4.tabBarItem = view4TabBarItem;
[view4TabBarItem release];
UIViewController *view5 = [[UIViewController alloc] init];
UITabBarItem *view5TabBarItem = [[UITabBarItem alloc] initWithTitle:@"5" image:[UIImage imageNamed:@"icon5.png"] tag:nil];
view5.tabBarItem = view5TabBarItem;
[view5TabBarItem release];
UIViewController *view6 = [[UIViewController alloc] init];
UITabBarItem *view6TabBarItem = [[UITabBarItem alloc] initWithTitle:@"6" image:[UIImage imageNamed:@"icon6.png"] tag:nil];
view6.tabBarItem = view6TabBarItem;
[view6TabBarItem release];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:view4,view5,view6,nil];
[view4 release];
[view5 release];
[view6 release];
tabView.viewControllers = viewControllers;
[viewControllers release];
[self presentModalViewController:tabView animated:YES];
[tabView release];
+1
source

Source: https://habr.com/ru/post/1776778/


All Articles