UINavigationController里面的UITabBarController里面的UITableViewController

use*_*602 4 objective-c uitabbarcontroller uitableview uinavigationcontroller ios

我的问题

我在UINavigationController中使用UITabBarController.UITabBarController中有三个tableviews.如图所示,第一个表视图正确显示,而其他两个tableviews部分隐藏在导航栏后面.我怎样才能解决这个问题?

在此输入图像描述 在此输入图像描述 在此输入图像描述

我的等级:

  • Root:UINavigationController
    • 的UITabBarController
      • UITableViewController(table1,table2,table3)

这是我的代码:

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

con*_*are 5

通常,层次结构是

UITabBarController
    - UINavigationController
        - UITableViewController
Run Code Online (Sandbox Code Playgroud)

你为什么要把导航控制器放在最上面?尝试使用充满导航控制器的标签栏重新组织.