11
一個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
})
最終的動畫塊顯示形式的錯誤。
Cannot invoke 'animateWithDuration' with an argument list of type '(NSTimeInterval), animations:()-> Void)'
如果我稱之爲完成關閉之外的某個地方,它可以工作。
非常感謝=)!! – 2014-09-24 17:06:07
這對我來說是固定的,但是有人會介意解釋*爲什麼這種行爲對於很多人來說是如此奇怪和令人意想不到的?順便說一句,在你的例子中,你可以用'_'替換'() - > Void',並用';'追加返回。返回'到同一行。另外,你可以寫'; ()'而不是單行'return'。 :) – BastiBen 2014-12-17 10:41:58
這是正確的答案! – 2015-01-25 16:08:32