gpt4 book ai didi

ios - 为已经启动的 View Controller 执行带有标识符的 Segue

转载 作者:行者123 更新时间:2023-11-29 12:30:37 25 4
gpt4 key购买 nike

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

当我使用 pushVC 时,安装 VC 效果很好,但是当我使用 perform segue with identifier 时,我没有看到选择已经实例化的 VC 的选项。

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

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

https://github.com/AlvaroFranco/AFBlurSegue

最佳答案

I need to instantiate the view controller with properties before I present the view controller.

为什么在触发 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];

关于ios - 为已经启动的 View Controller 执行带有标识符的 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27835905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com