Xcode 4.5.1 中的搜索栏在我输入内容时崩溃,而当我使用 Xcode 4.4 时它工作得很好,请帮忙
我使用了这个代码,它是另一个问题的答案,当我使用 Xcode 4/4 时它工作得很好,直到我将它更新到 4.5.1
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar{
//Perform the JSON query.
[self searchCoordinatesForAddress:[theSearchBar text]];
//Hide the keyboard.
[theSearchBar resignFirstResponder];}
-(void) searchCoordinatesForAddress:(NSString *)inAddress{
NSMutableString *urlString = [NSMutableString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=json",inAddress];
//Replace Spaces with a '+' character.
[urlString setString:[urlString stringByReplacingOccurrencesOfString:@" " withString:@"+"]];
NSURL *url = [NSURL URLWithString:urlString];
//Setup and start an async download.
//Note that we should test for reachability!.
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *error;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSArray *placemark = [results objectForKey:@"Placemark"];
NSArray *coordinates = [[placemark objectAtIndex:0] valueForKeyPath:@"Point.coordinates"];
double longitude = [[coordinates objectAtIndex:0] doubleValue];
double latitude = [[coordinates objectAtIndex:1] doubleValue];
[self zoomMapAndCenterAtLatitude:latitude andLongitude:longitude];}