使用侧栏菜单时,UITableView正在无意中向下移动〜1英寸

我在我的应用程序中有一个奇怪的错误,它使用带有UITableView的边栏菜单来列出button来导航。 当我开始我的应用程序, 一切看起来不错,是在正确的地方 。

一旦我select了相应的viewController, and navigate back to sidebar menu the UITableView` 下移约1英寸 。

如果我按侧栏菜单buttonclosures它,菜单重置,一切正常,看起来很正常。 这个错误只发生一次,一旦我select一个行,导航回到它,closures它, UITableView将在正确的位置,直到用户硬重启应用程序。 任何想法是怎么回事?

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

 #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 ”网站上查看了侧边栏代码的教程。

此外,我testing了其他对象,如button和标签,他们不移动,它只有移动的UITableView

谢谢!

我find了解决scheme! 这与导航控制器的设置有关。 这里到期的信用。

容器视图被推下来,就像它有一个UINavigationBar?

您需要检查导航栏设置下是否选中“半透明”。

尝试添加self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);viewDidLoad 。 这可能是一个解决scheme,如果你的应用程序自动添加插入。

  1. 尝试在视图控制器中设置self.automaticallyAdjustsScrollViewInsets = NO
  2. 尝试将edgesForExtendedLayout设置为UIRectEdgeNone

希望能帮助到你。