【问题标题】:mapViewDidLoad method not loaded未加载 mapViewDidLoad 方法
【发布时间】:2012-08-03 04:12:45
【问题描述】:

目标 c 的新手,我在地图部分使用 ArcGIS。我有一个问题,方法mapViewDidLoad 没有被调用/加载。以下是部分代码:

.h 文件

@interface ViewController : UIViewController<AGSMapViewLayerDelegate, AGSMapViewTouchDelegate, AGSMapViewCalloutDelegate>{
AGSMapView *_mapView;
AppDelegate *appDelegate;
...
}

.m 文件

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.activityView startAnimating];
    self.mapView.touchDelegate = self;
    self.mapView.calloutDelegate = self;
    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    ...
}

- (void)mapViewDidLoad:(AGSMapView *)mapView {

    AGSEnvelope *envelope = [[AGSEnvelope alloc]initWithXmin:29757.610204117
                                                    ymin:40055.0379682464
                                                    xmax:29884.6992302249
                                                    ymax:40236.6028660071
                                        spatialReference:self.mapView.spatialReference];
    [self.mapView zoomToEnvelope:envelope animated:YES];

    self.mapView.callout.width = 195.0f;
    self.mapView.callout.accessoryButtonHidden = YES;

    [self.mapView.gps start];
    [self.mapView centerAtPoint:self.mapView.gps.currentPoint animated:YES];   
    NSLog(@"Location : %@", self.mapView.gps.currentPoint);

    [self.activityView stopAnimating];
    self.activityView.hidden = YES;

}

我的代码有什么问题,为什么我没有加载mapViewDidLoad 方法。 提前致谢。

【问题讨论】:

  • 确保将 mapview 连接到插座,并在您的情况下将其作为文件所有者的 delegate = self
  • 是的,出口 mapView 已经连接到文件所有者。我的每个插座都连接到它们的适当位置
  • 并且mapview的代理也被分配给文件所有者仔细检查这一步
  • 地图视图的代理不在插座中

标签: iphone objective-c ios xcode4.3 arcgis


【解决方案1】:

只需在viewDidLoad 中添加self.mapView.delegate = self;

【讨论】:

  • 如果我添加这个Property 'delegate' not found on object of type 'AGSMapView *'会出错
【解决方案2】:

确保通过右键单击 mapview 连接 mapviewdelegate 然后分配委托..

或添加[self.mapview setDelegate:self];

在您的情况下,“AGSMapView”mapViewDidLoad:在将第一层添加到地图后调用 AGSMapViewLayerDelegate 上的方法。此时,组件功能齐全,您可以在 http://help.arcgis.com/en/arcgismobile/10.0/apis/iphone/reference/interface_a_g_s_map_view.html

使 self.mapview.layerDelegate = self;

【讨论】:

  • 我在出口部分没有代表,我添加了[self.mapview setDelegate:self];,它给了我一个警告'AGSMapView' may not respond to 'setDelegate',它在运行时崩溃,Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AGSMapView setDelegate:]: unrecognized selector sent to instance 0x90afc00'
  • 试试 [self.mapview setAGSMapViewDelegate:self];
  • 也适用于 self.mapview.mapViewDelegate = self
  • 其中一个将为您工作并触发您的 mapViewDidLoad 方法
  • [self.mapview setAGSMapViewDelegate:self];,警告Instance method '-setAGSMapViewDelegate' not found(return type defaults to 'id' self.mapview.mapViewDelegate = self,收到错误Property MapViewDelegate not found on object of type 'AGSMapView *'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-28
  • 2015-09-16
相关资源
最近更新 更多