【发布时间】:2012-01-06 12:54:04
【问题描述】:
当我单击 PIN 上的右侧标注时,我想移动到一个名为 DetailsThemes 的新视图控制器,但是,当我这样做时:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self.navigationController pushViewController:self.detailsThemes animated:YES];
}
我收到了这个错误:
Property detailsThemes not found on object of type 'ViewController *';
did you mean to access ivar 'detailsThemes'?
虽然,detailsThemes 是 DetailsThemes 的一个实例,它是一个 UIViewController 类,但在我的类中,我确实调用了 DetailsThemes 类,文件顶部带有 @class DetailsThemes;,如下所示:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@class DetailsThemes;
@interface ViewController : UIViewController<MKMapViewDelegate>
{
DetailsThemes * detailsThemes;
}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end
编辑:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped: %@",view.annotation);
[self.navigationController pushViewController:self.detailsThemes animated:YES];
}
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"ManageAnnotations";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
[annotationView setAnimatesDrop:YES];
annotationView.canShowCallout = YES;
//annotationView.pinColor = ((ManageAnnotations *)annotation).pinColor;
annotationView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeInfoLight];
return annotationView;
}
【问题讨论】:
-
您是否阅读了错误信息?读两遍,有解释。您必须为 detailsThemes 声明 @property 或直接访问 ivar。
-
我做到了,好吧,现在我一切正常,但是,当我点击 PIN 的右侧信息按钮时,我什么也没有,详情视图不收费。
-
calloutAccessoryControlTapped 真的被调用了吗?在里面放一个 NSLog 或者断点来确定。
-
嗨,我已经编辑了我的帖子,实际上,
calloutAccessoryControlTapped被调用了,这就是为什么我有点困惑,我已经为详细信息类声明了一个属性,但我什么也没得到,详细信息视图当我点击 PIN 的信息按钮时没有被推上去。
标签: objective-c uiviewcontroller ios5 storyboard