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 8962317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:06:07+00:00 2026-06-15T16:06:07+00:00

I m doing the concept of autocomplete feature for a textField and in doing

  • 0

I m doing the concept of autocomplete feature for a textField and in doing so I m getting the following error:
“cfstring length message sent to deallocated instance”

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   if( textField == txtcity)
    {

     autocompleteTableView.hidden = NO;

     NSString *substring = [NSString stringWithString:textField.text];
    substring = [substring stringByReplacingCharactersInRange:range withString:string];
    [self searchAutocompleteEntriesWithSubstring:substring];
    return YES;
    }
}

- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {

    subString2=[NSString stringWithFormat:@"%@",substring];


    NSMutableData *data = [[NSMutableData alloc] init];
    self.receivedData = data;
    [data release];

    NSURL *jsonUrl =[NSURL URLWithString:[NSString stringWithFormat:@"http://210.90.32.122/services/AutoService.svc/GetCities/?p=%@&k=%@",substring,txtId.text]];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:jsonUrl];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
                                                                  delegate:self];
     self.connection = connection;
    [connection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

{
    [receivedData setLength:0];

}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{
    [receivedData appendData:data];

}



- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    parser = [[NSXMLParser alloc] initWithData:receivedData];
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    [parser parse];
    [parser release];
    NSLog(@"%@",arr2);
    if([arr2 count]!=0)
    {

        self.autocompleteUrls = [[NSMutableArray alloc] init];
        if(autocompleteTableView)
            [autocompleteTableView removeFromSuperview];
        autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(88, 428, 200,[arr2 count]*20) style:UITableViewStyleGrouped];
        autocompleteTableView.delegate = self;
        autocompleteTableView.dataSource = self;
        autocompleteTableView.scrollEnabled = YES;
        autocompleteTableView.rowHeight=20;

        [self.view addSubview:autocompleteTableView];
               for(int i=0;i<[arr2 count];i++)
        {
            NSString *curString = [[arr2 objectAtIndex:i] valueForKey:@"Name"];

            NSRange substringRange = [curString rangeOfString:subString2];  //error at this line 

            if (substringRange.location == 0)
                [autocompleteUrls addObject:curString];

        }
    }


    [autocompleteTableView reloadData];
    txtcity.text=subString2;
    [txtcity resignFirstResponder];

}

my subString2 is becoming null.But I have retained it while decalring

@property(nonatomic,retain)NSString *subString2;

Where Im going wrong.Couldn’t understand where it is being deallocated..

  • 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-06-15T16:06:08+00:00Added an answer on June 15, 2026 at 4:06 pm

    You’re not actually retain it. You’re setting the object variable subString2 not though the property, that is the reason. Try this:

    self.subString2 = [NSString stringWithFormat:@"%@",substring];
    

    But it is not very good practise to get to the object variables from the object through the properties. There is two options:

    [subString2 release];
    subString2 = [[NSString stringWithFormat:@"%@",substring] copy];
    
    OR
    
    [subString2 release];
    subString2 = [[NSString stringWithFormat:@"%@",substring] retain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a hibernate error. I am just doing a proof of concept
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
I'm doing a proof of concept app in SL4 using MEF and as part
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following
I'm doing some proof-of-concept work with Spring MVC and security. So far I've managed
To try the concept, I'm doing a very simple test. I got a form
Background We're doing a proof-of-concept around Sharepoint 2007. It's installed using VMWare on Windows
I've got a proof-of-concept program which is doing some interprocess communication simply by writing
The concept of this seems easy, but I'm having trouble getting it right and

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.