【问题标题】:Push another view when click on rightCalloutAccessoryView单击右CalloutAccessoryView时推送另一个视图
【发布时间】: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'?

虽然,detailsThemesDetailsThemes 的一个实例,它是一个 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


【解决方案1】:

在您的ViewDidLoad 方法中,您必须首先分配您的DetailsThemes,然后在您的调用中使用它。如果您仍然没有成功,请发布您的 callOutAccessoryView 代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多