Note that there are some explanatory texts on larger screens.

plurals
  1. POCLLocation iVar looses value, becomes null halfway through the program
    text
    copied!<p>this is my first post, but I read the site all the time. I am working on a program that deals with passing a CLLocation* between multiple classes. It begins with my app delegate finding the current location with the CLLocationManager. Once the location is found, the didUpdateToLocation: newLocation: fromLocation method sets this location to another class called queryPage:</p> <pre><code>//AppDelegate.m -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *) newLocation fromLocation:(CLLocation *)oldlocation { currentLocation = newLocation; [queryPage setLocation:currentLocation]; } </code></pre> <p>Here, I can log the location, and everything works fine. Then, in queryPage, setLocation can receive the CLLocation and log it, no problem. However, later in my code, methods like button1 and button2 have trouble accessing currentLocation. button1 can log it sometimes, and button2 usually logs "(null)". Here is QueryPage.h:</p> <pre><code>//QueryPage.h #import &lt;CoreLocation/CoreLocation.h&gt; #import &lt;MapKit/MapKit.h&gt; @interface QueryPage : UIViewController { CLLocation *currentLocation; } @property (nonatomic, retain) CLLocation *currentLocation; -(void)setLocation:(CLLocation*)location; </code></pre> <p>and the implenentation file:</p> <pre><code>//QueryPage.m #import QueryPage.h @implementation QueryPage @synthesize currentLocation; ... -(void)setLocation:(CLLocation*)location { self.currentLocation = location; } ... -(IBAction)button1:(id)sender { NSLog(@"button1: %@", currentLocation); } ... -(IBAction)button2:(id)sender { NSLog(@"button2: %@", currentLocation); } </code></pre> <p>I think that I must be setting/retaining currentLocation the wrong way, but I have no idea how. I have searched for days trying to handle the memory properly and this is as far as I have gotten. I tried retaining currentLocation and many other things I could find online. I know that the connections in IB are good (I log it each time they are touched), and currentLocation is always set before any buttons are touched (I can see it in the log). If anyone out there can help me with this, please let me know. This looks similar to some other problems on the forum, but I have tried everything that has been recommended so far. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload