0
我在做自動完成功能的概念,一個文本框,並在這方面,我m到處以下錯誤: 「CFString字符串長度的消息發送到釋放實例」cfstring長度的消息發送到解除分配的實例?
- (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];
}
我subString2變得null.But我有在decalring中保留它
@property(nonatomic,retain)NSString * subString2;
在哪裏,我要去wrong.Couldn't明白的地方它被釋放..
請發佈堆棧跟蹤。 – trojanfoe
CFString length]:發送到釋放實例的消息0x81cb450 – Honey