gpt4 book ai didi

Swift - ButtonWithType 和 as 的问题

转载 作者:行者123 更新时间:2023-11-30 12:29:15 28 4
gpt4 key购买 nike

var view: MKPinAnnotationView
view.rightCalloutAccessoryView = UIButton.buttonWithType(.DetailDisclosure) as! UIView

我是 swift 新手。当我遵循在线教程( https://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial )时,上述代码的第二行给了我以下问题;

  1. buttonWithType 无法识别。因此我使用了 type buttonType: UIButtonType 但它仍然给我一个错误

  2. 在同一行代码中 as! 会生成错误。

最佳答案

语法在 swift 3 中发生了变化,你可以使用

view.rightCalloutAccessoryView  = UIButton(type: .detailDisclosure)

并且作为 UIButton 类继承自 UIView 类,因此您不需要强制将其强制转换(as!)到 UIView 中。

希望对你有帮助!

关于Swift - ButtonWithType 和 as 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43796684/

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