Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在协议中找不到_Iphone_Objective C_Cocoa - Fatal编程技术网

Iphone 在协议中找不到

Iphone 在协议中找不到,iphone,objective-c,cocoa,Iphone,Objective C,Cocoa,我已将MKAnnotation子类化,以便可以将对象指定给注释,然后将此对象指定给视图控制器,如下所示: - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { PlaceDetailView *detailView = [[PlaceDetailView alloc] initWit

我已将MKAnnotation子类化,以便可以将对象指定给注释,然后将此对象指定给视图控制器,如下所示:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

    PlaceDetailView *detailView = [[PlaceDetailView alloc] initWithStyle:UITableViewStyleGrouped];
    detailView.place = [view.annotation place];
    [self.navigationController pushViewController:detailView animated:YES];
    [detailView release];

}
这很有效,但我有以下问题:

  • 如果我尝试访问place getter方法,如so
    view.annotation.place
    我收到一个错误:

    访问未知位置getter方法

  • 如果我像这样访问place getter方法
    [view.annotation place]
    我会收到一条警告:

    在协议中找不到位置


据我所知,这是因为place对象没有在MKAnnotation协议中定义,尽管我知道这一点,但我不确定如何告诉编译器place确实存在,并且它不是盲目的

如果您确定
视图.annotation
始终是您的自定义类,那么您可以将其强制转换为您的类:

MyAnnotation *my = (MyAnnotation *)view.annotation;
detailView.place = my.place;

非常好,谢谢,在您编辑答案之前,我已经找到了所需的细微改动,并且它编译时包含0个警告:)