My Problem
I am using a UITabBarController inside a UINavigationController. And there are three tableviews inside the UITabBarController. As shown in the picture, the first table view shows correctly while the other two tableviews are partially hidden behind the navigation bar. How can I fix this?
My hierarchy:
- Root: UINavigationController
- UITabBarController
- UITableViewController (table1,table2,table3)
- UITabBarController
Here is my code:
AppDelegate.m
#import "AppDelegate.h"
#import "TableViewController.h"
@interface AppDelegate()
@property UINavigationController* nav;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
TableViewController* table1 = [[TableViewController alloc]init];
TableViewController* table2 = [[TableViewController alloc]init];
TableViewController* table3 = [[TableViewController alloc]init];
table1.title = @"table1";
table2.title = @"table2";
table3.title = @"table3";
UITabBarController* t = [[UITabBarController alloc] init];
[t setViewControllers:@[table1,table2,table3]];
self.nav = [[UINavigationController alloc] initWithRootViewController:t];
[self.window setRootViewController:self.nav];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application{}
- (void)applicationDidEnterBackground:(UIApplication *)application{}
- (void)applicationWillEnterForeground:(UIApplication *)application{}
- (void)applicationDidBecomeActive:(UIApplication *)application{}
- (void)applicationWillTerminate:(UIApplication *)application{}
@end
TableViewController.m
#import "TableViewController.h"
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style{
self = [super initWithStyle:style];
if (self) {}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
[self.tabBarController.view layoutSubviews];
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* c = [[UITableViewCell alloc] init];
[c.textLabel setText:[NSString stringWithFormat:@"%d", indexPath.row]];
return c;
}
@end