I am new to Objective-C and I am trying to write my first iOS app. The idea is quite simple, but I didn’t work at the beginning of building the architecture.
I would like to create different views displayed on several tabs that should be dynamically created when the view loads. In addition, the application should be able to dynamically add tabs at run time. Table views should not go all over the screen, but should fill 2/3 of the top view. The remaining 1/3 at the bottom is again divided into two sub-items, which are not intended to be changed using the tablet switches.
What I did was create a UIWindow, a UITabBarController and two UIViewControllers (for two tabs) and one (or two, as shown), which should be at the bottom.
So far I have managed to switch between different types of tabs, but as soon as I try to resize the UIViewControllers for both tabs from CGMakeRect to any size, it always stays the same and covers the entire screen.
The view created below contains a button that somehow cannot be pressed. Maybe because it is closed from the tab views.
Can someone help me a little, how can I create these views?
Thanks a lot!
Here is my code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UIViewController *test = [[UIViewController alloc] init]; test.view.backgroundColor = [UIColor grayColor]; test.view.frame = CGRectMake(0, 0, 320, 200); UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button3 setTitle:@"View 3" forState:UIControlStateNormal]; button3.frame = CGRectMake(30.0, 30.0, 120.0, 50.0); [test.view addSubview:button3]; UITabBarController *tabBarController = [[UITabBarController alloc] init]; UIViewController *viewController1 = [[UIViewController alloc] init]; UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1]; [viewController1 setTabBarItem:tab1]; UIViewController *viewController2 = [[UIViewController alloc] init]; UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:2]; [viewController2 setTabBarItem:tab2]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:@"View from Tab 1" forState:UIControlStateNormal]; button.frame = CGRectMake(100.0, 100.0, 120.0, 50.0); [viewController1.view addSubview:button]; UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button2 setTitle:@"View from Tab 2" forState:UIControlStateNormal]; button2.frame = CGRectMake(100.0, 100.0, 120.0, 50.0); [viewController2.view addSubview:button2]; tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; self.window.rootViewController = tabBarController; [self.window addSubview:test.view]; [self.window makeKeyAndVisible];