MKMapView - 加载更多结果时未调用 viewForAnnotation
编辑添加 * 我还没有找到这个问题的解决方案,有人可以帮忙吗?我的问题与此类似,但发布的答案对我不起作用 - MKMapView 在 pin 后刷新移动 *结束编辑
我有一个启用搜索的地图视图。当用户点击搜索时,我的自定义注释将添加到地图视图中。搜索返回 20 个带有“加载更多”链接的结果。当我点击加载更多时,应该将更多注释添加到地图视图中。
问题是 - 注释被添加到地图视图中,但没有显示在地图上。如果我放大或缩小以更改地图区域,则会显示图钉。
我发现当我点击“加载更多”时, viewForAnnotations: 没有被调用。我不知道如何触发这个。任何一个吗?
-(void)completedSearch:(NSNotification *)resultNotification
{
//begin loop
//get coordinate
customAnnotation *annot = [[customAnnotation alloc] initWithCoordinate:coordinate];
//set title subtitle
[annotationsArray addObject:annot];
//end loop
[mView addAnnotations:annotationsArray];
[mView setRegion:region animated:YES];
[mView regionThatFits:region];
}
//custom annotation
@interface customAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString* title;
NSString* info;
}
@property (nonatomic, retain) NSSting *title;
@property (nonatomic, retain) NSSting *info;
-(id) initWithCoordinate:(CLLocationCoordinate2D)c;
@end
@implementation customAnnotation
@synthesize coordinate, title, info;
-(id) initWithCoordinate:(CLLocationCoordinate2D)c
{
coordinate = c;
return self;
}
-(void)dealloc{//dealloc stuff here}
@end
Edited to Add * I haven't found a solution for this one yet, can anyone please help? My problem is similar to this but the answer posted doesn't t work for me - MKMapView refresh after pin moves *End Edit
I have a search enabled map view. When user hits search, my custom annotations are added to the map view. The search returns 20 results with a 'load more' link. When I hit load more, more annotations should be added to map view.
The problem is - annotations gets added to the map view but is not displayed on the map. If I zoom in or zoom out to change the map region, the pins are shown.
I find that viewForAnnotations: is not getting called when i hit 'load more'. I am not sure how to trigger this. any one?
-(void)completedSearch:(NSNotification *)resultNotification
{
//begin loop
//get coordinate
customAnnotation *annot = [[customAnnotation alloc] initWithCoordinate:coordinate];
//set title subtitle
[annotationsArray addObject:annot];
//end loop
[mView addAnnotations:annotationsArray];
[mView setRegion:region animated:YES];
[mView regionThatFits:region];
}
//custom annotation
@interface customAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString* title;
NSString* info;
}
@property (nonatomic, retain) NSSting *title;
@property (nonatomic, retain) NSSting *info;
-(id) initWithCoordinate:(CLLocationCoordinate2D)c;
@end
@implementation customAnnotation
@synthesize coordinate, title, info;
-(id) initWithCoordinate:(CLLocationCoordinate2D)c
{
coordinate = c;
return self;
}
-(void)dealloc{//dealloc stuff here}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是想确认
我正在从线程添加注释 - 这不起作用。
一旦我使用了这个(addCameraIconOnMain 添加了我的注释),
它就起作用了!谢谢!
just wanted to confirm
i was adding annotations from a thread - which doesnt work.
once I used this (addCameraIconOnMain adds my annoations)
its worked! thanks!
这与接收通知然后添加注释引脚的时间间隔有关。强制它使用主线程添加注释引脚是有效的。
This had something to do with the time lapse receiving the notification and then adding the annotation pins. Forcing it to use the main thread to add annotation pins worked.
就我而言,问题是我在地图委托之前添加注释。它一定是这样的:
in my case the problem was I was adding the annotation before the map delegate. It must be something like: