gpt4 book ai didi

ios - 如何在 Swift 中使用 dismissViewControllerAnimated 中的完成处理程序?

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

在将应用程序从 Objective-C 重构为 Swift 时,我遇到了一个问题,我无法自行解决。

ViewControllerOne 有方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue 发件人:(id)sender。在此方法中,我设置 destinationViewController:
ViewControllerTwo *viewControllerTwo = [segue destinationViewController];
和一些像这样的 block 处理程序:

[viewControllerTwo setHandlerOne:^(id sender) {
[...]
}]

然后,当触摸按钮时,我将显示模态视图。在模态视图 Controller ViewControllerTwo 中,我将关闭此模态视图:

- (IBAction)buttonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
self.handlerOne(sender);
}

在 Swift 代码中我设置了相同的内容:
ViewControllerOne 方法:
覆盖 funcprepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
设置destinationViewController
让 vc = segue.destinationViewController 作为! ViewControllerTwo
和代码块:

vc.setHandlerOne { () -> Void in
[...]
}

这样我得到错误类型'ViewControllerTwo'的值没有成员'setHandlerOne'。我在这里缺少什么?我必须在 viewControllerTwo 中手动设置它吗?

最佳答案

我认为您的destinationViewController不是ViewControllerTwo类型,或者如果您的destinationViewController是ViewControllerTwo类型,那么ViewControllerTwo不包含setHandlerOne方法,则可能是可能的。

关于ios - 如何在 Swift 中使用 dismissViewControllerAnimated 中的完成处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37191385/

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