This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
When instantiated from nib, MGLAnnotationView doesn't call the delegate methods when tapped #7747
Labels
annotations
Annotations on iOS and macOS or markers on Android
bug
iOS
Mapbox Maps SDK for iOS
needs information
Comments
Can you include a snippet of your |
sure: func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
// This example is only concerned with point annotations.
guard annotation is MGLPointAnnotation else {
return nil
}
// Use the point annotation’s longitude value (as a string) as the reuse identifier for its view.
let reuseIdentifier = "\(annotation.coordinate.longitude)"
// For better performance, always try to reuse existing annotations.
var annotationView:MGLAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier) as? NowrAnnotationView
// If there’s no reusable annotation view available, initialize a new one.
if annotationView == nil {
let nib = UINib(nibName: "NowrAnnotationView", bundle: Bundle.main)
//annotationView?.reuseIdentifier = reuseIdentifier -> not allowed since it's read only
annotationView = nib.instantiate(withOwner: self, options: nil).first as! NowrAnnotationView
}else{
debugPrint("reusing view!")
}
/*
if annotationView == nil {
annotationView = NowrAnnotationView(reuseIdentifier: reuseIdentifier)
}else{
debugPrint("reusing view!")
}
annotationView?.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
*/
//annotationView!.bubbleView.isHidden = true
return annotationView! as MGLAnnotationView
} and the subclass: class NowrAnnotationView: MGLAnnotationView {
@IBOutlet weak var imgNowr: UIImageView!
@IBOutlet weak var bubbleView: UIView!
@IBOutlet weak var lblEmoticons: UILabel!
override func layoutSubviews() {
super.layoutSubviews()
// Force the annotation view to maintain a constant size when the map is tilted.
scalesWithViewingDistance = false
imgNowr.animationImages = [UIImage(named:"00.png")!, UIImage(named:"01.png")!, UIImage(named:"02.png")!, UIImage(named:"03.png")!, UIImage(named:"04.png")!]
imgNowr.contentMode = .scaleAspectFit
imgNowr.animationDuration = 1
imgNowr.startAnimating()
// Force the annotation view to maintain a constant size when the map is tilted.
scalesWithViewingDistance = false
}
|
I tried overriding the identifier, but the callout doesn't work. var annotationView:NowrAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier) as? NowrAnnotationView
// If there’s no reusable annotation view available, initialize a new one.
if annotationView == nil {
let nib = UINib(nibName: "NowrAnnotationView", bundle: Bundle.main)
annotationView = nib.instantiate(withOwner: self, options: nil).first as! NowrAnnotationView
annotationView?.reuseIdentifier = reuseIdentifier
}else{
debugPrint("reusing view!")
} |
Found the issue. The variable Try adding
|
ouch! it works 😁 |
@frederoni is this by design, or should this be considered a bug/feature? thanks ! |
I'm going to reopen this since I think it'd be worthwhile to review how annotation views created with Interface Builder work with our view reuse system. Especially after #6559 which manipulates the value of |
boundsj
added
annotations
Annotations on iOS and macOS or markers on Android
needs information
bug
labels
Jan 17, 2017
Closing in favor of #7751 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
annotations
Annotations on iOS and macOS or markers on Android
bug
iOS
Mapbox Maps SDK for iOS
needs information
Platform:
iOs
Mapbox SDK version:
3.3.7
Steps to trigger behavior
Expected behavior
The delegate methods should be called
Actual behavior
They don't get called. I have to instantiate the view using code, and init(withIdentifier). Since I cannot "set" the identifier after the view gets created instantiating the nib, could this be the problem?
The text was updated successfully, but these errors were encountered: