【发布时间】:2011-08-07 08:56:40
【问题描述】:
在我的
- (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];
它工作得很好。他们不做同样的事情吗?
【问题讨论】:
标签: iphone objective-c uitableview release autorelease