1

我通过代码添加了一个 UINavigationController,但它在顶部留下了一个间隙.. 大约 20 px .. 在此处输入图像描述

如果我切换到其他选项卡并返回此选项卡,它会消失,但是在导航栏移动到正确位置之前大约 0.2 秒可以看到它。

我已经搜索 StackOverflow 但我找不到解决方案...

这是我的代码的一部分:

appDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    .....
    UIViewController *vc1 = [[Tab1 alloc] initWithNibName:@"Tab1" bundle:nil];
    UIViewController *vc2 = [[FreshEpisodeController alloc] initWithNibName:@"FreshEpisodeController" bundle:nil];
    UIViewController *vc3 = [[Tab3 alloc] initWithNibName:@"Tab3" bundle:nil];
    UIViewController *vc5 = [[DownloadListController alloc] initWithNibName:@"DownloadListController" bundle:nil];
    self.tabBarController = [[UITabHost alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:vc2, vc1, vc3, vc5, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    .....
}

Tab3.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [[self view] addSubview:mNavController.view];
        self.title = NSLocalizedString(@"Collection List", @"Collection List");
        self.tabBarItem.image = [UIImage imageNamed:@"tab3"];
    }
    return self;
}

在 Tab3.xib 中,我有一个UIViewUINavigationController(mNavController)

如果我将 Tab3 设置为第一次显示(我将其放在第一个选项卡上),则间隙不存在,但如果我将其放在第二个选项卡上,它会显示我是否切换到查看 Tab3。

4

4 回答 4

1

在ViewControllerAttributes部分中将Under Top Bars属性设置为未选中可能会有所帮助。

于 2013-08-28T13:00:58.897 回答
0

尝试这样做

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [[self view] addSubview:mNavController.view];
        mNavController.view.frame = self.view.bounds; //here you assign the subView frame to fit superView area
        self.title = NSLocalizedString(@"Collection List", @"Collection List");
        self.tabBarItem.image = [UIImage imageNamed:@"tab3"];
    }
    return self;
}
于 2012-05-23T08:46:40.367 回答
0

将视图控制器的“wantsFullScreenLayout”属性设置为“YES”

于 2012-05-23T07:36:05.727 回答
-1

添加UINavigationController (mNavController)withviewDidLoad方法,代码应该是这样的:

- (void)viewDidLoad {
    [super viewDidLoad];

    [[self view] addSubview:mNavController.view];
    self.title = NSLocalizedString(@"Collection List", @"Collection List");
    self.tabBarItem.image = [UIImage imageNamed:@"tab3"];
}

现在享受......

于 2012-05-23T08:09:33.130 回答