2010-05-22 34 views
0

我创建了一个uitableview来计算表格中位置的距离。我在索引路径的行中使用此代码。在uitableview中打印两次的文本

 NSString *lat1 = [object valueForKey:@"Lat"]; 

    NSLog(@"Current Spot Latitude:%@",lat1); 

    float lat2 = [lat1 floatValue]; 
    NSLog(@"Current Spot Latitude Float:%g", lat2); 

    NSString *long1 = [object valueForKey:@"Lon"]; 

    NSLog(@"Current Spot Longitude:%@",long1); 

    float long2 = [long1 floatValue]; 
    NSLog(@"Current Spot Longitude Float:%g", long2); 

    //Getting current location from NSDictionary 

    CoreDataTestAppDelegate *appDelegate = (CoreDataTestAppDelegate *) [[UIApplication sharedApplication] delegate]; 
    NSString *locLat = [NSString stringWithFormat:appDelegate.latitude]; 
    float locLat2 = [locLat floatValue]; 
    NSLog(@"Lat: %g",locLat2); 

    NSString *locLong = [NSString stringWithFormat:appDelegate.longitude]; 
    float locLong2 = [locLong floatValue]; 
    NSLog(@"Long: %g",locLong2); 

    //Location of selected spot 
    CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2]; 

    //Current Location 
    CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:locLat2 longitude:locLong2]; 

    double distance = [loc1 getDistanceFrom: loc2]/1600; 

    NSMutableString* converted = [NSMutableString stringWithFormat:@"%.1f", distance]; 

    [converted appendString: @" m"]; 

它工作正常,除了我刚刚发现了一个问题,当你浏览其他页面的高度距离文本被复制过详细的文字标签的顶部。

这里是我的意思的屏幕截图。

任何想法为什么这样做?

回答

0

我看不到屏幕截图,但是我看不到您的代码用于创建字符串的问题。至少如果你使用垃圾收集 - 如果你正在使用手动内存管理,你想保留/释放。这也可能是您的.xib文件中的表配置问题。最后,你是使用任何自定义视图还是标准的Cocoa控件?自定义控件有时会导致绘图/刷新问题。