이것은 몇 시간 동안 나를 괴롭 히고 있으며 그것을 파악할 수 없었습니다.UITableView에서 행을 어떻게 삭제합니까?
코어 데이터와 NSMutableArray를 사용하여 데이터를 테이블 뷰로 가져옵니다. 아래 그림과 같이.
CORE 데이터 배열 I가 일정 거리 내에있는 결과를 표시하는 데에만 표를 얻기 위해 노력하고
- (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;
}
NSMutableArray *mutableFetchResults = [CoreDataHelper getObjectsFromContext:@"Spot" :@"Name" :YES :managedObjectContext];
self.entityArray = mutableFetchResults;
표보기. 이 방법은 특정 거리에 대한 결과가 아직 테이블에 남아 있고 그래픽으로 표시되지 않는다는 점을 제외하고는 작동합니다.
필자는 테이블을 포맷하기 전에 필터링 프로세스를 수행해야하지만이 작업을 수행 할 수 없다고 생각하게되었습니다.
도와주세요. 내 xcode 기술은 훌륭하지 않으므로 코드 제안이 도움이 될 것입니다.
이하지만 어떻게 내가 필터링 된 배열을 만드는 방법에 대해 가야합니까? – James
나는 당신을 사랑한다! 꿈처럼 작동합니다. – James
@James : 사랑의 표현은 훌륭하지만, 다른 사람들에게 그들의 감사를 표하는 표준 방법은 올바른 답을 수락하는 것입니다. :) –