DetailDisclosure 按钮未显示在注释视图中
由于某种奇怪的原因,详细信息按钮以某种方式停止出现:
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
MKPinAnnotationView *pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"sadasdasd"];
if ( pinAnnotation == nil ){
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"sadasdasd"] autorelease];
/* add detail button */
NSLog(@"Here");
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
}
return pinAnnotation;
}
这是输出。 提前致谢。
For some odd reason the detail button somehow stopped appearing:
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mapView.userLocation)
{
MKPinAnnotationView *pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"sadasdasd"];
if ( pinAnnotation == nil ){
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"sadasdasd"] autorelease];
/* add detail button */
NSLog(@"Here");
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
}
return pinAnnotation;
}
Here is output.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题是
pinAnnotation
在该方法中声明了两次。一次在第一行,第二行在
if(annotation != mapView.userLocation)...
块中。因此,return
语句返回nil
,因为外部变量从未设置(导致默认的MKAnnotationView
标注没有附件)。将第二个声明更改为赋值。
下一个问题是您需要将
canShowCallout
设置为YES
,因为MKPinAnnotationView
的默认值为NO
。您可以在设置附件视图后执行此操作:上面应该修复附件按钮不显示的问题。
不相关,但在重用视图时(在出队后不为 nil 的情况下),您还需要设置视图的
annotation
属性。因此,将else
块添加到if (pinAnnotation == nil)
中:First problem is that
pinAnnotation
is declared twice in that method.Once in the first line and second in the
if(annotation != mapView.userLocation)...
block. Because of this, thereturn
statement returnsnil
because the outer variable is never set (resulting in a defaultMKAnnotationView
callout with no accessory).Change the second declaration to just an assignment.
Next problem is that you need to set
canShowCallout
toYES
because the default isNO
for anMKPinAnnotationView
. You can do this after setting the accessory view:The above should fix the accessory button not showing.
Unrelated, but you also need to set the view's
annotation
property when it is being re-used (in the case when it is not nil after the dequeue). So add anelse
block to theif (pinAnnotation == nil)
: