何かを入力するとXcode 4.5.1の検索バーがクラッシュし、Xcode 4.4を使用していたときに問題なく機能しました助けてください
別の質問に対する回答であるこのコードを使用しました.4.5.1に更新するまで、Xcode 4/4を使用していたときに問題なく動作しました.
- (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];}