导航栏和表格视图之间的黑条显示在iOS 6上

dvy*_*yio 1 objective-c uitableview uinavigationcontroller ios ios6

自从我开始使用iOS 6后,我似乎遇到了一个问题,这在使用iOS 5时没有出现.起初,我认为它可能只是一个模拟器错误,但是自从今天在我的iPhone 5上测试它,我可以看到它不只是在模拟器中.

我正在以编程方式创建所有内容 - 我似乎更喜欢这样做(我认为这是因为我的HTML/CSS背景!) - 但我仍然是Objective-C的新手,我找不到完整的示例如何以编程方式设置导航控制器/表视图,所以我把它放在我能找到的信息块中,因此,我可能会做一些根本错误的事情.但是,它在iOS 5上完美运行(并且仍然有效).

问题是我在导航栏和表视图之间有一个黑条,但奇怪的是,如果我按下一个视图并返回到原始视图,该条消失,并且在我完全重启之前不再出现该应用程序.

下面的图片是启动时的应用程序(1),因为我正在推动(2)中的视图,以及我回到它之后的初始视图(3):

这就是我的代码:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    RootViewController *rootController = [[RootViewController alloc] init];
    self.window.rootViewController = rootController;

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];

    NSLog(@"Window frame: %@", NSStringFromCGRect(self.window.frame));

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

RootViewController.m

- (void)loadView
{
    self.title = @"Title";

    self.tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.view = self.tableView;

    NSLog(@"tableView frame: %@", NSStringFromCGRect(self.tableView.frame));

    UIBarButtonItem *newViewButton = [[UIBarButtonItem alloc] initWithTitle:@"New View"
                                                                  style:UIBarButtonItemStylePlain
                                                                 target:self
                                                                 action:@selector(newViewButtonTapped:)];
    [self.navigationItem setRightBarButtonItem:newViewButton animated:NO];
}
Run Code Online (Sandbox Code Playgroud)

我添加了NSLogs,看看他们是否展示了可能对我有帮助的东西.输出是:

tableView frame: {{0, 0}, {320, 480}}
Window frame: {{0, 0}, {320, 480}}
Run Code Online (Sandbox Code Playgroud)

谁能给我任何关于我做错的想法?它似乎有一个类似/相同的问题(黑条超越导航栏 - 在评论中),但我还没有找到答案.

提前致谢!

tc.*_*tc. 5

您将RootViewController添加到窗口两次,一次是通过设置UIWindow.rootViewController(内部执行[window addSubview:rootViewController.view]),再次将其添加为导航控制器的子视图.

你应该这样做:

RootViewController *rootController = [[RootViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window.rootViewController = navigationController;
Run Code Online (Sandbox Code Playgroud)

根据经验,除非您知道自己真正想要的,否则永远不要将视图直接添加到窗口.