這一直困擾着我幾個小時,我一直無法弄清楚。如何從UITableView中刪除行?
我正在使用核心數據和NSMutableArray將數據導入tableview。如下所示。
核心數據ARRAY
NSMutableArray *mutableFetchResults = [CoreDataHelper getObjectsFromContext:@"Spot" :@"Name" :YES :managedObjectContext];
self.entityArray = mutableFetchResults;
表視圖
- (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;
}
我想只得到表中顯示的結果是在一定距離內。這種方法在這裏工作,除了一定距離的結果仍然在表格中,它們只是不可見的。
我被引導認爲我必須在格式化表格之前執行過濾過程,但我似乎無法執行此操作。
請幫忙。我的xcode技巧並不精彩,所以代碼建議會很有幫助。
我明白這一點,但如何我去創建過濾的數組? – James 2010-05-07 11:06:20
我愛你!像夢一樣工作 – James 2010-05-07 13:47:22
@詹姆斯:雖然愛的表達很棒,但感謝某人投入的標準方式是接受他們的回答是正確的。 :) – 2010-05-07 18:57:54