Swift - 如何根据按下的按钮显示不同的注释?

时间:2015-07-14 09:16:39

标签: swift mapkit mkannotation

所以我有这个代码,当我按下按钮时会显示所有注释。我想要做的是用多个按钮按类型显示每个注释。所以,让我说按下类型1的按钮,它将显示类型1的注释,当我按下类型2的按钮时,它将显示类型2的注释,依此类推......

func addAttractionPins() {
    let filePath = NSBundle.mainBundle().pathForResource("Attractions", ofType: "plist")
    let attractions = NSArray(contentsOfFile: filePath!)
    for attraction in attractions! {
        let point = CGPointFromString(attraction["location"] as! String)
        let coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(point.x), CLLocationDegrees(point.y))
        let title = attraction["name"] as! String
        let typeRawValue = (attraction["type"] as! String).toInt()!
        let type = AttractionType(rawValue: typeRawValue)!
        let subtitle = attraction["subtitle"] as! String
        let annotation = AttractionAnnotation(coordinate: coordinate, title: title, subtitle: subtitle, type: type)
        mapView.addAnnotation(annotation)
    }
}

0 个答案:

没有答案