iOS - 调用方法:[self.navigationController pushViewController: animated:],屏幕全黑

iOS - call the method : [self.navigationController pushViewController: animated:], the screen get whole black

我想通过在表格视图中选择一行来推送 SecViewController。我正在使用 Storyboard 来实现它。这是我的代码:

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

SecViewController *sec = [[SecViewController alloc] init];
[self.navigationController pushViewController:sec animated:NO];

}

这是我的故事板:

但是当我 运行 这个应用程序时: 出现这种情况:

为什么会这样?

按如下方式更改您的代码:

SecViewController *sec = [self.storyboard instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];

[self.navigationController pushViewController:sec animated:NO];

viewControllerIdentifier 更改为该视图控制器的故事板标识符..

希望对您有所帮助..

请检查:

  • 您的按钮必须添加约束,或者正确设置大小和原点
  • 您的按钮已添加到正确的超级视图中
  • 如果你有这样的看法 viewController :)(一定要尝试更改背景色)