开发者

iPhone - MKOverlay and MKOverlayView logic

开发者 https://www.devze.com 2023-03-31 03:53 出处:网络
There\'s a point I wonder, maybe someone could explain me with simple words better than the doc do...

There's a point I wonder, maybe someone could explain me with simple words better than the doc do...

When you want to add an overlay onto a MKMapView, you first add something that follow the MKOverlay protocol.

Then later, (MKOverlayView*)mapView:(MKMapView*)mapView viewForOverla开发者_如何学运维y:(id)overlay is called and you must return a MKOverlayView or something that inherits it.

What is the role of the overlay added in addOverlay as it does not display anything ? Why not directly add a subview as it's done with addSubview for views and put "inside it" the needed vars for the display ? Why running with such a 2 part process ?


In the model-view-controller (MVC) pattern, objects that store data are isolated from objects that handle presentation: The role of the object that implements MKOverlay is to manage data storage, and the role of the MKOverlayView object is to handle presentation on a map.

For instance, you might have an ApartmentBuilding object that stores data about tenants, rents, property taxes, and so on, and you might want to use that object in an app that displays your real estate empire on a map – but you might also want to use the same ApartmentBuilding data in an app that calculates your tax bill, or that produces a calendar of scheduled maintenance.

If the code that models your ApartmentBuilding is cleanly separated from the code that displays your building on a map, then you can pair up your ApartmentBuilding model with a different view object – a MaintenanceCalendarView, say, or a TaxSpreadsheetView – and your code is easier to maintain and re-use.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号