是否有可能从MKPolyline继承 [英] Is it possible to inherit from MKPolyline

查看:81
本文介绍了是否有可能从MKPolyline继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone构建一个基于MapKit的应用程序。

I'm building a MapKit based app for iPhone.

我在地图上添加了许多MKPolylines。

I have a number of MKPolylines added to the map.

然而,我想让我自己的Model类符合添加到地图中的MKOverlay协议,而不是拥有MKPolyline,这样我就可以访问模型属性了。在mapView中创建相应的视图:viewForOverlay。

However, instead of having a MKPolyline, I would like to have my own Model class conforming to the MKOverlay protocol added to the map so that I can access the model properties when creating the corresponding view in mapView:viewForOverlay.

问题是我无法找到从MKPolyline继承的方法,因为它没有任何init方法可以从子类'init调用。您只能使用便捷方法创建它们。

The problem is that I can't find the way to inherit from MKPolyline because it doesn't have any init methods that I can call from the subclass' init. You can only create them using the convenience methods.

如何将模型属性和MKPolyline行为结合在一起?

How can I bring together the model properties and the MKPolyline behaviour?

推荐答案

你可以设置类的关联对象属性。这允许您将实例变量绑定到现有类。确保你自己正确清理。

You can set an associated object attribute of the class. This allows you to bind an instance variable to an existing class. Make sure you properly clean up after yourself.

这篇关于是否有可能从MKPolyline继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆