gpt4 book ai didi

uiview - 嵌套闭包不喜欢参数列表

转载 作者:IT王子 更新时间:2023-10-29 05:28:24 25 4
gpt4 key购买 nike

UIView 需要根据自定义控件的完成处理程序更改警告标签:

    voucherInputView.completionHandler = {[weak self] (success: Bool) -> Void in

self?.proceedButton.enabled = success
self?.warningLabel.alpha = 1.0

if success
{
self?.warningLabel.text = "Code you entered is correct"
self?.warningLabel.backgroundColor = UIColor.greenColor()
}
else
{
self?.warningLabel.text = "Code you entered is incorrect"
self?.warningLabel.backgroundColor = UIColor.orangeColor()
}


UIView.animateWithDuration(NSTimeInterval(1.0), animations:{ ()-> Void in
self?.warningLabel.alpha = 1.0
})

最后的动画 block 显示了表单中的一个错误。

Cannot invoke 'animateWithDuration' with an argument list of type '(NSTimeInterval), animations: ()-> Void)'

如果我在完成闭包之外的某个地方调用它,它就可以工作。

最佳答案

问题是闭包隐式返回了这个表达式的结果:

self?.warningLabel.alpha = 1.0

但是闭包本身被声明为返回 Void

添加一个明确的 return 应该可以解决问题:

UIView.animateWithDuration(NSTimeInterval(1.0), animations: { ()-> Void in
self?.warningLabel.alpha = 1.0
return
})

关于uiview - 嵌套闭包不喜欢参数列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26022052/

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