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

时间:2016-05-10 14:15:46

标签: ios objective-c uitableview storyboard pushviewcontroller

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

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

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

}

这是我的故事板: enter image description here

但是当我运行这个应用程序时: 看来这种情况: ViewController SecViewController

为什么会这样?

2 个答案:

答案 0 :(得分:4)

更改您的代码如下:

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

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

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

希望有所帮助......

答案 1 :(得分:0)

请检查:

  • 您的按钮必须添加约束,或者正确设置尺寸和原点
  • 您的按钮已添加到正确的超级视图中
  • 如果你在viewController中有一个视图:)(尝试改变backgorund颜色,不确定)