2017-05-05 20 views
0
var view: MKPinAnnotationView 
view.rightCalloutAccessoryView = UIButton.buttonWithType(.DetailDisclosure) as! UIView 

問題我是新來的swift。在我參加在線教程(https://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial)時,上面代碼的第二行給出了以下問題;Swift - 使用buttonWithType和

  1. buttonWithType未被識別。因此我使用的是buttonType: UIButtonType,但它仍然給我一個錯誤

  2. 在同一行代碼as!產生一個錯誤。

+0

鏈接教程中的代碼是用Swift 2編寫的。如果您使用的是Swift 3,則需要將代碼轉換爲新的語法。 – vadian

回答

0

句法在3迅速改變,你可以使用

view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) 

的UIButton類從的UIView類繼承,所以你並不需要強制投(爲! )它變成一個UIView。

希望它有幫助!

相關問題