mva*_*sco 0 objective-c selector ios
我在viewDidLoad方法中有一个NSTimer:
timer = [NSTimer scheduledTimerWithTimeInterval: 10.0
target: self
selector: @selector(refrescar_vehiculo_asignado:)
userInfo: nil
repeats: YES];
Run Code Online (Sandbox Code Playgroud)
启动的选择器是这样的:
-(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];
}
}
}
}];
}
Run Code Online (Sandbox Code Playgroud)
此方法首先在viewDidLoad方法中启动,没有任何问题,但是当它在预定时间启动时,它会抛出异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapaConductor refrescar_vehiculo_asignado:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
我无法找到问题来源.
这是因为您指定的选择,像这样:refrescar_vehiculo_asignado:但你只实现等的方法:refrescar_vehiculo_asignado.
通过删除冒号来查看差异,该冒号指示方法是否接受参数.
| 归档时间: |
|
| 查看次数: |
41 次 |
| 最近记录: |