使用侧边栏菜单时,UITableView 无意中向下移动了约 1 英寸 [英] UITableView is shifting down ~1inch unintentionally when using using sidebar menu

查看:23
本文介绍了使用侧边栏菜单时,UITableView 无意中向下移动了约 1 英寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个奇怪的错误,它使用带有 UITableView 的侧边栏菜单来列出要导航的按钮.当我启动我的应用程序时,一切看起来都很好并且在正确的位置.

I'm having a weird bug in my app that uses a sidebar menu with a UITableView to list buttons to navigate. When I start my app, everything looks fine and is in the correct place.

一旦我选择了相应的 viewController,并导航回侧边栏菜单UITableView` 向下移动了大约 1 英寸.

Once I make a selection to the respective viewController, and navigate back to sidebar menu theUITableView` is shifted down about 1 inch.

如果我按下侧边栏菜单按钮将其关闭,菜单会重置并且一切正常且看起来正常.这个错误只会发生一次,一旦我选择一行,导航回它,关闭它,UITableView 将处于正确的位置,直到用户重新启动应用程序.知道发生了什么吗?

If I press the sidebar menu button to close it, the menu resets and everything works and looks normal. This bug only happens once, once I select an row, navigate back to it, close it, the UITableView will be in the correct position until the user hard restarts the app. Any idea whats going on?

这是我的侧边栏菜单代码:

Here is my code for the sidebar menu:

#import "SideBarViewController.h"

@interface SideBarViewController ()

@end

@implementation SideBarViewController

@synthesize controllerArray, sidebarButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    controllerArray = [NSArray arrayWithObjects:@"Search For Games", @"Login", @"Library", nil];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [controllerArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [controllerArray objectAtIndex:indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIViewController *selection;

    if (indexPath.row == 0) {
        selection = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchController"];
        [self.navigationController pushViewController:selection animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    else if (indexPath.row == 1) {
        selection = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginController"];
        [self.navigationController pushViewController:selection animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    else if (indexPath.row == 2) {
        selection = [self.storyboard instantiateViewControllerWithIdentifier:@"LibraryController"];
        [self.navigationController pushViewController:selection animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }

}

我按照Ray Wenderlich"网站上的教程获取侧边栏代码.

I followed the tutorial on the "Ray Wenderlich" website for sidebar code.

此外,我测试了其他对象,例如按钮和标签,它们不会移动,只有 UITableView 会移动.

Also, I've tested other objects, such as buttons and labels and they do not move, its only the UITableView that shifts.

谢谢!

推荐答案

我找到了解决方案!它与导航控制器的设置有关.此处欠款.

I found the solution! It had to do with the setting for the Navigation controller. Credit due here.

容器视图被推下好像它有一个 UINavigationBar?

您需要查看导航栏设置下是否勾选了半透明".

You need to check and see if "Translucent" is checked under the Navigation Bar settings.

这篇关于使用侧边栏菜单时,UITableView 无意中向下移动了约 1 英寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆