Reputation: 18237
I have a design problem. Here is what I want to do: I want to constraint MKMapView
to a specific region, while making it an abstraction for the view controller which want to actually work with the map.
To constraint the map view I most likely want to use the delegate method mapView:regionDidChangeAnimated:
and get notified of the changes and move the map back if the region is out of my pre-determined region. However, since I want to make it generic enough I don't want the code to be in view controller. I thought I might want to sub-class MKMapView instead.
If I do that I would have a subclass of MKMapView
(say, a ConstraintMapView
class) which is also the delegate of MKMapView
and expose the methods to constraint the region to any user of the class. But then the user of the class (say a view controller) would also expect to be a delegate of MKMapView
, so I would also want to forward all delegate messages to the view controller.
To do so I need a delegate property which points to the real delegate (the view controller), but in my ConstriantMapView
if I have one does that mean I'm overriding the MKMapView
's setter and getter to the delegate and things get kind of complicated because inside MKMapView
it could call ConstraintMapView
's methods and I would give it the view controller but I really want to give it ConstraintMapView
instead.
Upvotes: 1
Views: 1203
Reputation: 5128
I have done a similar proxying MKMapViewDelegate
in this project; check it out:
https://github.com/mapbox/mbxmapkit
Upvotes: 1
Reputation: 83
If you want to over right an Existing class, you can use "The decorator design pattern". Here is the brief explanation.
http://www.raywenderlich.com/46988/ios-design-patterns
Hope It helps
Upvotes: 0