AddressAnnotation 可能不会响应 initWithCooperative
我的程序在 IOS 4.0 上运行良好,但是在 IOS 5.0 上运行时出现以下警告:
“AddressAnnotation 可能无法响应 initWithCooperative”。
如何更改以下部分:
“addAnnotation = [[AddressAnnotation alloc] initWithCooperative:location];”
AddressAnnotaion.m
- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
coordinate = c;
NSLog (@"%f,%f",c.latitude,c.longitude);
return self;
}
MapViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
.......
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta =0.005;
span.longitudeDelta =0.005;
CLLocationCoordinate2D location = mapView.userLocation.coordinate;
location.latitude = [lat doubleValue];
location.longitude = [lon doubleValue];
region.span = span;
region.center = location;
if (addAnnotation !=nil) {
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
addAnnotation.title = companyTitle;
[mapView addAnnotation:addAnnotation];
[mapView selectAnnotation:addAnnotation animated:YES];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}
my program work well on IOS 4.0, however run on IOS 5.0 have the warning as below:
"AddressAnnotation may not respond to initWithCoordinate."
how to change for below this part:
"addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];"
AddressAnnotaion.m
- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
coordinate = c;
NSLog (@"%f,%f",c.latitude,c.longitude);
return self;
}
MapViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
.......
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta =0.005;
span.longitudeDelta =0.005;
CLLocationCoordinate2D location = mapView.userLocation.coordinate;
location.latitude = [lat doubleValue];
location.longitude = [lon doubleValue];
region.span = span;
region.center = location;
if (addAnnotation !=nil) {
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
addAnnotation.title = companyTitle;
[mapView addAnnotation:addAnnotation];
[mapView selectAnnotation:addAnnotation animated:YES];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保在
AddressAnnotation.h
文件中声明initWithCooperative:
方法:另外,实现 init 方法的更标准方法如下:
Make sure the
initWithCoordinate:
method is declared in theAddressAnnotation.h
file:Also, a more standard way to implement an init method is like this: