Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:57:04+00:00 2026-05-31T00:57:04+00:00

I’ve got a UIPickerView object that lists stores based on either a listed home

  • 0

I’ve got a UIPickerView object that lists stores based on either a listed “home” location or one’s current location (using CLLocationManager). If the latter is implemented, I make a NSMutableURLRequest to my server to get the closest stores, then update a UIPickerView with the received list.

On occasion, (and oddly enough never when I’m at the “home” location), I will use the current location, I’ll see the picker update the list, then the app immediately crashes.

My picker code is simple enough:

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (isHome) {
        return [storesData count];
    } else {
        return [storesDataLoc count];
    }
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (isHome) {
        return [[storesData objectAtIndex:row] objectForKey:@"STName"];
    } else {
        return [[storesDataLoc objectAtIndex:row] objectForKey:@"STName"];
    }
}

One thought was that it was providing a second, more accurate reading and that I was releasing something that I may have already released. My CLLocationManager code is:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if (error.code == kCLErrorLocationUnknown) {
    NSLog(@"Currently unable to retrieve location");
} else if (error.code == kCLErrorNetwork) {
    NSLog(@"Network used to retrieve location is unavailable");
} else if (error.code == kCLErrorDenied) {
    NSLog(@"Permission to retrieve location is denied");
    [locMan stopUpdatingLocation];
    [locMan release];
    locMan = nil;

    // revert segmented controller to Home position
    storeSource.selectedSegmentIndex = 0;
}
if(loadstoresconnection!=nil){
    [loadstoresconnection release];
}
networkView.hidden = TRUE;
isHome = TRUE;
}

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation {

if (newLocation.horizontalAccuracy >= 0) {
    networkView.hidden = TRUE;
    if (newLocation.horizontalAccuracy < 200) {
        [locMan stopUpdatingLocation];
        [locMan release];
        locMan = nil;
    }

    //call for store list from this location
    NSString *myString = [NSString stringWithFormat:@"http://mywebsite.com/?lat=%f&lng=%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude];
    NSURL *myURL = [[NSURL alloc] initWithString:[myString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
    loadstoresconnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
}

And the pertinent NSMutableURLRequest methods are:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[responseData release];
[connection release];
networkView.hidden = TRUE;
isHome = YES;
//    [textView setString:@"Unable to fetch data"];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
int i;
NSArray *querydata;

networkView.hidden = TRUE;
[loadstoresconnection release];
if (storesDataLoc!=nil) {
    [storesDataLoc release];
    storesDataLoc = nil;
}
storesDataLoc = [[NSMutableArray alloc] init];
NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
[responseData release];
// put data into variables.
querydata = [txt componentsSeparatedByString:@"<-sl->"];//break up data into data sections: 0 - number of deptsections and names, 1 - list of objects
NSArray *allstoreinfo;
for (i=0; i<[querydata count]; i++) {
    allstoreinfo = [[querydata objectAtIndex:i] componentsSeparatedByString:@"<-as->"];
    [storesDataLoc addObject:[[[NSMutableDictionary alloc] initWithObjectsAndKeys:[allstoreinfo objectAtIndex:0],@"STid",[allstoreinfo objectAtIndex:1],@"STName",[allstoreinfo objectAtIndex:2],@"STAddr",nil] autorelease]];
}
if ([querydata count]>0) {
    [pickerView reload];
    [pickerView selectRow:0 inComponent:0 animated:NO];
    isHome = NO;
}    

}

Im curious as to why I can see the picker being updated just before the crashes. Because this happens when I’m on the road, I’m suspecting it’s an accuracy thing, and location manager is sending a second result, causing the crash. Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:57:06+00:00Added an answer on May 31, 2026 at 12:57 am

    It appears I was trying to do too much of a shortcut. When the user hit the location button, it would turn on the LocationManager, which with every result would set up an NSURLConnection to my server. I was bring to handle all this in a single class, but with the multiple results the location manager would return, NSURLConnections seemed to be uncontrolled. I have since put each location manager result in its own class and everything is working honky dory. So, no issue with the picker – mainly a memory issue with location manager and nsurlconnections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.