AddressAnnotation 可能不会响应 initWithCooperative

发布于 2024-12-14 00:47:29 字数 1222 浏览 0 评论 0原文

我的程序在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淤浪 2024-12-21 00:47:29

确保在 AddressAnnotation.h 文件中声明 initWithCooperative: 方法:

@interface AddressAnnotation : NSObject<MKAnnotation>
{
    //ivars here...
}

//properties here...

- (id) initWithCoordinate: (CLLocationCoordinate2D) c;  //<-- add this

@end

另外,实现 init 方法的更标准方法如下:

- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
    self = [super init];
    if (self) {
        coordinate = c;
        NSLog (@"%f,%f",c.latitude,c.longitude);
    }
    return self;
}

Make sure the initWithCoordinate: method is declared in the AddressAnnotation.h file:

@interface AddressAnnotation : NSObject<MKAnnotation>
{
    //ivars here...
}

//properties here...

- (id) initWithCoordinate: (CLLocationCoordinate2D) c;  //<-- add this

@end

Also, a more standard way to implement an init method is like this:

- (id) initWithCoordinate: (CLLocationCoordinate2D) c {
    self = [super init];
    if (self) {
        coordinate = c;
        NSLog (@"%f,%f",c.latitude,c.longitude);
    }
    return self;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文