How do you delete rows from UITableView?

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-05-07T00:39:06Z Indexed on 2010/05/07 0:48 UTC
Read the original article Hit count: 282

Filed under:
|
|
|

This has been bugging me for hours now and i have not been able to figure it out.

I am importing data into a tableview using core data and NSMutableArray. As shown below.

CORE DATA ARRAY

NSMutableArray *mutableFetchResults  = [CoreDataHelper getObjectsFromContext:@"Spot" :@"Name" :YES :managedObjectContext];
self.entityArray = mutableFetchResults;

TABLE VIEW

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSManagedObject *object = (NSManagedObject *)[entityArray objectAtIndex:indexPath.row];

    NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }



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

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

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

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

    //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);

    //Distance Shizzle
    //Prime's Location
    CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
    //Home Location
    CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:locLat2 longitude:locLong2];

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

    int myInt = (int)(distance + (distance>0 ? 0.5 : -0.5));

    //NSLog(@"INT VAL :%i", myInt);

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

    [converted appendString: @" Km"];

    //NSLog(@"Distance between Prime and home = %g", converted);

    if (myInt < 11) {
        cell.textLabel.text = [object valueForKey:@"Name"];
        cell.detailTextLabel.text = [NSString stringWithFormat:converted];
    }
    else {


    }

    // Configure the cell...

    return cell;
}

I am trying to get the table only to display results that are within a certain distance. This method here works apart from the fact that the results over a certain distance are still in the table, they are just not graphically visible.

I am led to believe that i have to carry out the filtering process before the formatting the table but i can not seem to do this.

Please help. My xcode skills are not brilliant so code suggestions would be helpfull.

© Stack Overflow or respective owner

Related posts about core

Related posts about database