【问题标题】:Perform Segue With Identifier for already Instiated View Controller为已经启动的视图控制器执行带标识符的 Segue
【发布时间】:2015-01-08 16:55:12
【问题描述】:

我正在尝试使用自定义 segue(在底部)以模态方式呈现具有模糊视图的视图控制器。在呈现视图控制器之前,我需要使用属性实例化视图控制器。

当我使用 pushVC 时,初始化 VC 效果很好,但是当我使用带有标识符的执行 segue 时,我看不到选择已经实例化的 VC 的选项。

    CustomViewController* VC = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"customVC"]; 
    [self.navigationController performSegueWithIdentifier:@"blurSegue" sender:self];

如何执行自定义 segue 并强制它使用我分配的视图控制器(上面称为 VC)?

https://github.com/AlvaroFranco/AFBlurSegue

【问题讨论】:

  • 为什么要先实例化视图控制器?
  • @nburk 因为它的页面集合 VC 并基于数组属性加载它的页面
  • @DyanaJuliana 这不应该是必要的!查看我的答案以了解详细信息:)
  • 还有什么不清楚的地方吗?我的回答有帮助吗?
  • 谢谢,这工作!!!! CustomViewController *customViewController = (CustomViewController *)segue.destinationViewController;是关键线

标签: ios objective-c iphone uistoryboard


【解决方案1】:

我需要先用属性实例化视图控制器 呈现视图控制器。

为什么要在触发segue之前实例化CustomViewController。这应该不是必需的,如果您需要访问CustomViewController属性 在显示之前,您可以在prepareForSegue 中设置它。

试试这个:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"blurSegue"]) {
        CustomViewController *customViewController = (CustomViewController *)segue.destinationViewController;
        customViewController.propertyToSet = XXX; // set the property here
    }
}

啊,顺便说一下,不是

[self.navigationController performSegueWithIdentifier:@"blurSegue" sender:self];

只需使用:

[self performSegueWithIdentifier:@"blurSegue" sender:self];

【讨论】:

  • 'CustomViewController* VC = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"CustomerCardCollectionView"];'替换以下内容:'CustomViewController* VC = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"customVC"];'
  • 对不起,你问什么?如果您要发布代码,请更新答案,而不是将其放入 cmets! :)
猜你喜欢
  • 1970-01-01
  • 2018-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-16
  • 2016-12-31
  • 1970-01-01
相关资源
最近更新 更多