-1

Currently using Xcode 6;

While generating map view in iOS 8.1 using Mapkit.h and coreLocation framework,on clicking the button instead of showing latitude and longitude values in labels it's showing crash error as:unrecognized selector sent to instance 0x797a4e20

in GPSController.m

- (IBAction)tap:(id)sender {

    NSLog(@"button clicked");
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];
    [locationManager startMonitoringSignificantLocationChanges];

}

should fetch the value in this:

 (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{
    NSLog(@"location info object=%@", [locations lastObject]);
    CLLocation* location = [locations lastObject];

    NSLog(@"latitude %+.6f, longitude %+.6f\n",
          location.coordinate.latitude,
          location.coordinate.longitude);
    self.lat.text = [NSString stringWithFormat:@"%+.6f", location.coordinate.latitude];
    self.longi.text = [NSString stringWithFormat:@"%+.6f", location.coordinate.longitude];
    [self performSegueWithIdentifier:@"Map" sender:self];

}
kapil sachdeva
  • 37
  • 1
  • 10
  • 2
    Show the complete error message. It should be telling you the exact class and selector that is unrecognized. You should also identify exactly which line it crashes on. –  Mar 09 '15 at 11:14
  • Go to the breakpoints tab (Cmd+7), press `+` and add an `Exception Breakpoint`. Now it should crash on the line which calls the unrecognised selector. – Lord Zsolt Mar 09 '15 at 11:18
  • Error Log:[GPSViewController locationError:]: unrecognized selector sent to instance 0x7a979070 (lldb) – kapil sachdeva Mar 09 '15 at 11:26
  • - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { [self.delegate locationError:error]; //error at this point } – kapil sachdeva Mar 09 '15 at 11:28
  • what is self.delegate ?? is it implementing the method() locationError: – AppleDelegate Mar 09 '15 at 11:30
  • [code](import #import "CoreLocation/CoreLocation.h" - (void)update:(CLLocation *)location; - (void)locationError:(NSError *)error; NSObject ) //CoreLocationController.h – kapil sachdeva Mar 09 '15 at 11:34
  • **Show the complete error message and exception stack trace!!!** These should *always* be included when reporting an Objective-C runtime error (or one in any other language, for that matter). – Hot Licks Mar 09 '15 at 12:51

2 Answers2

0

you should also give definition of

(void)locationError:(NSError *)error in{

//your logic }

0

Perform following reviews in your code.

  1. Check if ‘tap’ IBAction is binded with some cocoa control element (say UIbutton touchUpInside event)
  2. Check if ‘tap’ IBAction has been declared in Class
  3. You may be using action:@selector(tap:) instead of action:@selector(tap)
  4. Handle didFailWithError delegate of Location Manager to get more detail about error Syntax:

    (void) locationManager: (CLLocationManager *)manager
 didFailWithError: (NSError *) error

  5. Check of Segue with ID ‘Map’ does exists

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177