In my
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Я рассчитываю расстояние между двумя точками, поэтому у меня есть
NSString *sDistance = [[NSString alloc] init];
if (curLat != 0) {
if (curLong != 0) {
double desLat = [[requestedDict objectForKey:@"latitude"] doubleValue];
double desLong = [[requestedDict objectForKey:@"longitude"] doubleValue];
double distance = sqrt(69.1*(desLat-curLat)*69.1*(desLat-curLat)+69.1*(desLong-curLong)*cos(curLat/57.3)*69.1*(desLong-curLong)*cos(curLat/57.3));
sDistance = [NSString stringWithFormat:@"(%.1f mi)",distance];
[[cell distanceLabel] setText:[NSString stringWithFormat:@"(%.1f mi)",distance]];
}
else{
sDistance = @"";
[[cell distanceLabel] setText:@""];
}
}
[sDistance release];
Когда я это делаю, я получаю ошибки exc_bad_access, но когда я меняю его на
NSString *sDistance = [[[NSString alloc] init] autorelease];
Это работает просто отлично. Разве они не делают то же самое?