views:

32

answers:

1

I have created a uitableview that calculates the distance of a location in the table. I used this code in cell for row at index path.

        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"];

It works fine apart from a problem i have just discovered where the distance text is duplicated over the top of the detailed text label when you scroll beyond the height of the page.

here's a screen shot of what i mean.

Any ideas why its doing this?

A: 

I can't see the screenshot, but I don't see a problem with your code used to create the string. At least if you're using garbage collection - if you're using manual memory management you'd want to retain/release. It also may be an issue in your .xib file with the table configuration. Finally, are you using any custom views or just standard Cocoa controls? Custom controls can sometimes cause drawing/refresh issues.

jfm429