SettingsViewController *viewController = [[SettingsViewController alloc] init];
[[self navigationController] pushViewController:viewController animated:YES];
在NavigationController中使用此代码时,显示的场景只是一个黑屏。在故事板中,它显示内容但不会显示在手机上。
答案 0 :(得分:18)
试试这个:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
SettingsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"setting"];
[self.navigationController pushViewController:viewController animated:YES];
将settingviewcontroller的标识符设置为“setting”
答案 1 :(得分:1)
使用此:
SettingsViewController *viewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:viewController animated:YES];
答案 2 :(得分:1)
一种简单的方法是通过实例化故事板。您必须为viewcontroller提供一个Storyboard ID,然后使用以下代码:
YourView *view = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewID"];
完成此操作后,只需按下:
[[self navigationController] pushViewController:view animated:YES];
希望这有帮助。
答案 3 :(得分:0)
试试这个
SettingsViewController *viewController = [[SettingsViewController alloc]initWithNibName:@"SettingsViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:viewController animated:YES];
答案 4 :(得分:0)
我通过目标视图控制器的自定义初始化解决了这个问题。
您的目标视图控制器:
-(id) initWithSender:(UINavigationController*)sender
{
self=[sender.storyboard instantiateViewControllerWithIdentifier:@"DestinationVCIdentifier"];
if (self) {
//custom initialisation
}
return self;
}
使用它:
DestinationVC *viewController = [[SettingsViewController alloc] initWithSender:self.navigationController];
[[self navigationController] pushViewController:viewController animated:YES];
答案 5 :(得分:0)
您好,您可以为视图控制器设置顶部栏属性(导航栏)为推断。在我的情况下,我之前将顶部栏设置为"半透明导航栏"
通常,您会从模态视图控制器执行segue。
答案 6 :(得分:0)
因此您可以使用xib或storyboard的名称初始化,因为每个人都在建议并且这是有效的。
虽然如果你正在使用故事板并且你的初始视图控制器在故事板上,他们可能会做以下事情,
// Method in your initial viewcontroller
- (void)youPushMethod {
// Name your segue on your storyboard, e.g. SegueIndentifier
[self performSegueWithIdentifier:@"SegueIndentifier" sender:self];
}
然后,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@“SegueIndentifier"]) {
SettingsViewController *settingsViewController= segue.destinationViewController;
}
}