似乎有3種不同的方式來編寫UIAlertAction的處理程序。每下方似乎做我希望他們同/預期的事情製作UIAlertAction的處理程序的正確方法
// 1.
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction!) -> Void in
print("a")
})
// 2.
let okAction = UIAlertAction(title: "OK", style: .Default, handler: { (action: UIAlertAction!) in
print("b")
})
// 3.
let okAction = UIAlertAction(title: "OK", style: .Default) { (action) in
print("c")
}
// OUTPUT:
// a
// b
// c
難道這些都使處理程序?有什麼區別,最適合使用?
這個鏈接應該幫助http://stackoverflow.com/questions/24190277/writing-handler-for-uialertaction – gurmandeep
@gurmandeep感謝。我仍然想明白爲什麼3.是最好的,他們之間的差異都是 – rdk
我同意@Joey。更多詳情請參閱https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertAction_Class/ – gurmandeep