【问题标题】:Call Storyboard without Segue在没有 Segue 的情况下调用 Storyboard
【发布时间】:2013-12-12 16:50:27
【问题描述】:

我正在尝试在不使用 Segue 的情况下推送 ViewController,但它不起作用。 我的按钮代码如下:

-(void)consultaButton
{
    NSString *storyboardName = @"Main";
    NSString *viewControllerID = @"Consultas";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
    EntradaViewController *controller = (EntradaViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
    [self presentViewController:controller animated:YES completion:nil];
}

EntradaViewController / Entrada = 原点 ViewController ConsultasViewController / Consultas = 目标 ViewController

我有错误:

2013-12-12 14:42:51.519 JuntaComercial[14285:70b] -[EntradaViewController consultaButton:]: unrecognized selector sent to instance 0x9e51650

有人可以帮我吗?我已经在使用 Segue 并且工作正常,但现在我需要在没有 Segue 的情况下做同样的事情。谢谢!!


更新(工作代码):

-(void)consultaButton:(id)sender
{
    NSString *storyboardName = @"Main";
    NSString *viewControllerID = @"Consultas";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
    EntradaViewController *controller = (EntradaViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
    [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentViewController:controller animated:YES completion:nil];
}

【问题讨论】:

  • 您项目中的 .storyboard 文件的名称是什么?这是为 storyboardName 设置的名称。
  • 已更新... Main.storyboard。但问题依然存在。
  • 我认为 Wain 可能正在做点什么。尝试将方法处理程序更改为:-(void)consultaButton:(id)sender,或者按照他的建议,修改按钮操作代码。
  • 工作安迪...非常感谢。最后一个问题......我怎样才能改变动画风格?
  • 在调用 presentViewController 之前,设置演示样式。例如。 [控制器 setModalPresentationStyle:UIModalPresentationPageSheet];

标签: ios uistoryboardsegue


【解决方案1】:

这似乎与故事板/segue 代码无关。相反,您有一个已配置操作的按钮,并且您已将操作设置为consultaButton:,但方法实际上是consultaButton(请注意缺少冒号,因为该方法没有参数。所以,更正方法签名或您设置为按钮操作的选择器。

【讨论】:

  • 我想做的只是从情节提要中删除 Segue。此按钮仅将用户从一个 ViewController 移动到另一个 ViewController。主菜单到搜索菜单。
猜你喜欢
  • 2018-01-21
  • 1970-01-01
  • 1970-01-01
  • 2013-11-07
  • 2018-06-16
  • 1970-01-01
  • 2016-03-08
  • 2012-02-08
  • 1970-01-01
相关资源
最近更新 更多