【问题标题】:presenting ViewController Programmatically in Storyboard在 Storyboard 中以编程方式呈现 ViewController
【发布时间】:2013-04-24 17:12:22
【问题描述】:

我正在尝试在情节提要中以编程方式呈现视图控制器,我正在使用下面提到的代码,但它不起作用,没有给我任何响应...

- (void)buttonPressed
{
NSLog(@"called");

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];

UINavigationController *vc = [sb instantiateViewControllerWithIdentifier:@"123"];

vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self.navigationController presentModalViewController:vc animated:YES];
}

我在这里错过了什么?

【问题讨论】:

  • 该代码看起来正确。你确定 self.navigationController 不等于 nil 吗?
  • but it's not working, doesn't give me any response...需要详细说明吗?
  • 我的应用程序有几个视图控制器,我有一个自定义状态栏,在状态栏的顶部,我有一个自定义的“清除”按钮,可以从任何视图控制器触发此方法。我想要的是当用户点击状态栏,我需要我的应用程序以模态方式将带有标识符 @"123" 的 viewController ...
  • 如您所见,我是 appDeveloping 和 StackOverflow 的新手,如果我遗漏了任何内容或您有任何问题,请询问......谢谢
  • 您为什么要展示来自self.navigationControllervc?如果你打电话给[self presentModalViewController:vc animated:YES] 会发生什么

标签: iphone ios objective-c uiviewcontroller uinavigationcontroller


【解决方案1】:
NSLog(@"called");

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    UINavigationController *vc = [sb instantiateInitialViewController];

    vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:vc animated:YES completion:nil];

【讨论】:

    猜你喜欢
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2021-09-07
    相关资源
    最近更新 更多