在两个类之间传递字符串不能正常工作

时间:2013-06-11 23:31:07

标签: ios objective-c google-places-api

我正在使用Google的适用于iOS的Places API,我需要将其中一个类(GooglePlacesConnection)中的字符串传递给GooglePlacesObject。

这里,在第一节课中,我将distanceMatrixURL设置为等于字符串timeURL

 timeURL = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/distancematrix/json?origins=%f,%f&destinations=%@,%@&sensor=true",userLat,userLng,destLat,destLng];

                GooglePlacesObject *googleplacesobject = [[GooglePlacesObject alloc]init];

                googleplacesobject.distanceMatrixURL = timeURL;
                NSLog(@"pullurl is %@",  googleplacesobject.distanceMatrixURL);

并且NSLog正确打印出googleplacesobject.distanceMatrixURL。 但是,在第二节课中,我做的时候

-(void)distanceMatrix{

NSLog(@"%@",distanceMatrixURL);

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:distanceMatrixURL]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10];


_connection2 = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
[_connection2 start];
if (_connection2)
{
    responseData2 = [NSMutableData data];
    connectionIsActive = YES;
    NSLog(@"connection is active with %@", responseData2);
} else {
    NSLog(@"connection failed");
}
}

NSLog的NSLog(@“%@”,distanceMatrixURL);是(null)

0 个答案:

没有答案