我在viewDidLoad方法中有一个NSTimer:
timer = [NSTimer scheduledTimerWithTimeInterval: 10.0
target: self
selector: @selector(refrescar_vehiculo_asignado:)
userInfo: nil
repeats: YES];
启动的选择器就是这个:
-(void) refrescar_vehiculo_asignado {
NSURL *apiURL = [NSURL URLWithString:
[NSString stringWithFormat:@"http://..hidden here../?employee=%@", _employee]];
NSURLRequest *request = [NSURLRequest requestWithURL:apiURL]; // this is using GET, for POST examples see the other answers here on this page
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if(data.length) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if(responseString && responseString.length) {
NSLog(@"dATOS RECIBIDOS=%@", responseString);
NSError *jsonError;
NSData *objectData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&jsonError];
NSArray *messageArray = [json objectForKey:@"objects"];
// Parse and loop through the JSON
for (dataDict in messageArray) {
NSString * latstring = [dataDict objectForKey:@"current_latitude"];
NSString * lonstring = [dataDict objectForKey:@"current_longitude"];
NSDictionary *level2Dict = [dataDict objectForKey:@"employee"];
id someObject = [level2Dict objectForKey:@"name"];
NSLog(@"NOMBRE===%@",someObject);
NSString * nombre = someObject;
latdouble = [latstring doubleValue];
londouble = [lonstring doubleValue];
CLLocationCoordinate2D vehiculo = [mapView centerCoordinate];
vehiculo.latitude = latdouble;
vehiculo.longitude = londouble;
PinAsignado *vehiculoDisponible = [[PinAsignado alloc] initWithTitle:@"Vehiculo disponible" location:vehiculo];
vehiculoDisponible.title = nombre;
[self.mapView addAnnotation:vehiculoDisponible];
[mapView selectAnnotation:vehiculoDisponible animated:NO];
}
}
}
}];
}
此方法首先在viewDidLoad方法中启动,没有任何问题,但是当它在预定时间启动时,它会引发异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapaConductor refrescar_vehiculo_asignado:]: unrecognized selector sent to instance
我无法找到问题来源。
答案 0 :(得分:6)
这是因为你指定选择器是这样的:refrescar_vehiculo_asignado:
但你只实现了一个方法:refrescar_vehiculo_asignado
。
通过删除指示方法是否接受参数的冒号来查看差异。