当我输入内容时,Xcode 5中的搜索栏崩溃了

时间:2012-10-28 00:28:40

标签: iphone xcode ios6 uisearchbar

当我输入内容时,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];}

0 个答案:

没有答案