gpt4 book ai didi

swift - 我如何使用 navigationController?.popViewController(动画 : true) inside of a closure with no warnings and errors?

转载 作者:搜寻专家 更新时间:2023-11-01 07:17:49 25 4
gpt4 key购买 nike

我知道在 swift 3 中是这样的:

navigationController?.popViewController(animated: true)

会产生这个警告:

"Expression of type "UIViewController?" is unused"

而且我知道消除此警告的推荐方法是执行以下操作:

_ = navigationController?.popViewController(animated: true)

但是当它在闭包中时:

myFunction(myParams: ["blah", "bleh"], callback: { myResult in
_ = navigationController?.popViewController(animated: true)
})

我收到这个错误:

Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit

如果我这样做:

myFunction(myParams: ["blah", "bleh"], callback: { myResult in
self.navigationController?.popViewController(animated: true)
})

我又收到警告了:

"Expression of type "UIViewController?" is unused"

如何在没有警告和错误的闭包内使用 navigationController?.popViewController(animated: true)?

最佳答案

你快到了!它只是结合您已经生产的产品:

myFunction(myParams: ["blah", "bleh"], callback: { myResult in
_ = self.navigationController?.popViewController(animated: true)
})

关于swift - 我如何使用 navigationController?.popViewController(动画 : true) inside of a closure with no warnings and errors?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41042898/

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