iPhone MapView 中的条件自定义注释视图
在我的 MapView 中,我从 SQLite 读取数据并在其上显示图钉(最多 5000 条记录)。
数据库的结构为 ID|经度|纬度 |标题 | 我使用此代码
使图钉可点击:
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
我需要在数据库中添加一个新列(可点击),并在“可点击”值为 ON 时使图钉可点击。
关于这样做的最佳想法有什么详细建议吗?
In my MapView, i read data from SQLite and display pins on it (up to 5000 record).
the database has the structure of ID| Longitude| Latitude | Title | subtitle
i used this code to make the pin clickable:
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
i need to add a new column (Clickable) in the database, and make the pin clickable just if the "Clickable" value is ON.
any detailed suggestion about the best idea to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,如果您未设置注释的任何属性(标题、副标题、图像、附件按钮)并点击图钉,则不会显示标注。
相反,如果您想显示标注但在点击附件按钮时不调用操作,您可以使用如下内容:(
从数据库下载数据后,您可以将每个项目存储为 NSDictionary code> 然后是
NSArray
中的所有项目)当然,我使用字符串作为示例,您也可以使用
NSNumber
或BOOL
。希望我理解你的问题。
From my experience if you don't set any property of the annotation (title,subTitle,image,accessory-button) and tap on the pin, the callout is not displayed.
Instead, if you want show the callout but not call an action when the accessory button is tapped, you could use a thing like this:
(After downloading the data from the db, you could store each item as a
NSDictionary
and then all items in aNSArray
)Of course I used a string as example, you may also use
NSNumber
s orBOOL
s.Hope i understood your question.
要根据表中的“clickable”标志控制标注是否具有附件按钮,我建议您向注释类添加一个
clickable
属性,并在添加注释时设置它。然后您可以在viewForAnnotation
方法中创建注释视图时检查此属性。要将注释添加到地图视图(即,当您调用
addAnnotation
时),如果您当前使用的是MKPointAnnotation
等预定义类,则需要改为定义您自己的实现 MKAnnotation 协议的自定义类。如果您已经有一个自定义类,请为其添加一个clickable
属性。下面是一个自定义注释类的示例:
这是一个如何创建和添加注释的示例(注释属性的实际值将来自您的 sql 行):
然后
viewForAnnotation
将如下所示 最后,您可以在 calloutAccessoryControlTapped 委托方法中处理按钮按下并访问自定义注释的属性:
To control whether the callout has the accessory button based on the "clickable" flag in the table, I suggest you add a
clickable
property to your annotation class and set it when adding the annotation. Then you can check this property when creating the annotation view in theviewForAnnotation
method.To add the annotations to the map view (ie. when you call
addAnnotation
), if you are currently using a pre-defined class likeMKPointAnnotation
, you'll need to instead define your own custom class that implements theMKAnnotation
protocol. If you already have a custom class, add aclickable
property to it.Here's an example of a custom annotation class:
Here's an example of how you would create and add the annotations (the actual values for the annotation properties will come from your sql rows):
Then the
viewForAnnotation
will look like this:Finally, you can handle the button press in the
calloutAccessoryControlTapped
delegate method and access your custom annotation's properties: