【问题标题】:How do I use navigationController?.popViewController(animated: true) inside of a closure with no warnings and errors?如何在没有警告和错误的闭包内使用 navigationController?.popViewController(animated: true)?
【发布时间】:2016-12-08 15:22:59
【问题描述】:

我知道在 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)?

【问题讨论】:

    标签: swift uiviewcontroller uinavigationcontroller swift3 closures


    【解决方案1】:

    你就快到了!它只是结合了您已经制作的内容:

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

    【讨论】:

    • 好吧,呃!!哎呀,这让我发疯了,谢谢!
    猜你喜欢
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2017-08-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    相关资源
    最近更新 更多