Iphone 在协议中找不到
我已将MKAnnotation子类化,以便可以将对象指定给注释,然后将此对象指定给视图控制器,如下所示: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
- (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
我收到一个错误: 访问未知位置getter方法view.annotation.place
- 如果我像这样访问place getter方法
我会收到一条警告: 在协议中找不到位置[view.annotation place]
据我所知,这是因为place对象没有在MKAnnotation协议中定义,尽管我知道这一点,但我不确定如何告诉编译器place确实存在,并且它不是盲目的 如果您确定
视图.annotation
始终是您的自定义类,那么您可以将其强制转换为您的类:
MyAnnotation *my = (MyAnnotation *)view.annotation;
detailView.place = my.place;
非常好,谢谢,在您编辑答案之前,我已经找到了所需的细微改动,并且它编译时包含0个警告:)