Ios 启动NSTimer时出现异常
我在viewDidLoad方法中有一个NSTimer:Ios 启动NSTimer时出现异常,ios,objective-c,selector,Ios,Objective C,Selector,我在viewDidLoad方法中有一个NSTimer: timer = [NSTimer scheduledTimerWithTimeInterval: 10.0 target: self selector: @selector(refrescar_vehiculo_asignado:)
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
我找不到问题源。这是因为您指定了如下选择器:
refrescar\u vehicleu\u asignado:
,但您只实现了一种方法:refrescar\u vehicleu\u asignado
删除冒号可以看出区别。冒号表示方法是否采用参数。这是因为您指定了如下选择器:
refrescar\u vehiculu\u asignado:
,但您只实现了以下方法:refrescar\u vehiculu\u asignado
删除冒号可以看出区别,冒号指示方法是否接受参数