Cela me dérange depuis des heures et je n'ai pas réussi à le comprendre. J'importe les données dans une vue de table en utilisant les données de base et NSMutableArray. Comme indiqué ci-dessous.Comment supprimer des lignes de UITableView?
DE DONNÉES DE BASE MATRICE
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;
}
Je suis en train d'obtenir la table que pour afficher les résultats qui sont à une certaine distance. Cette méthode fonctionne ici indépendamment du fait que les résultats sur une certaine distance sont toujours dans le tableau, ils ne sont tout simplement pas visibles graphiquement.
Je suis amené à croire que je dois effectuer le processus de filtrage avant le formatage de la table, mais je ne peux pas sembler faire cela.
Aidez-nous s'il vous plaît. Mes compétences xcode ne sont pas brillantes, donc les suggestions de code seraient utiles.
Je comprends cela, mais comment dois-je créer le tableau filtré? – James
JE T'AIME! Fonctionne comme un rêve – James
@James: Bien que les expressions de l'amour sont grands, la façon standard de remercier quelqu'un pour leur contribution est d'accepter leur réponse comme correcte. :) –