因此,我已經創建了一個名爲name
的屬性的表。第一個表格抓住名稱的不同值,因爲可以有多個相同的名稱。下一個表格視圖打開了這個特定值的重複項。指定了objectID的表中的核心數據副本
但是,我遇到的問題是從副本中獲取的信息只能從最新的伴隨屬性中獲取。所以他們都指向相同的信息。
以下是抓取放置在表格中的對象的方法。
AppDelegate.m
- (NSArray *)allLikePlaces:(id)place {
NSManagedObjectContext *moc = [[SVAppDelegate sharedAppDelegate] managedObjectContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Place" inManagedObjectContext:moc];
[fetch setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@", place];
[fetch setPredicate:predicate];
NSError *error;
NSArray *result = [moc executeFetchRequest:fetch error:&error];
if(error){
NSLog(@"allPlaces error: %@", [error localizedDescription]);
}
return result;
}
這是放置對象在表中的方法。
TableView.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
SVAppDelegate *ad = [SVAppDelegate sharedAppDelegate];
NSArray *list = [ad allLikePlaces:_place];
NSManagedObject *obj = list[indexPath.row];
cell.textLabel.text = [obj valueForKey:@"name"];
return cell;
}
我就能夠擁有這些對象,以顯示其相應的數據,而不僅僅是最新的記錄。
我一直在嘗試實施基於objectID
的實現,但沒有成功。我非常感謝在此方面的任何幫助。
我不明白你的目標是什麼。請更好地解釋你想達到的目標。樣品可以。 –
@flexaddicted對不起,我在表中選擇的數據然後輸出到'UIView'。發生的事情是,它只是用tableview抓取最後輸入的重複(使用屬性「name」)記錄的屬性。舉個例子。名稱是UNI,那麼表格中的所有單元格都會引用最後輸入的名稱UNI的記錄,而不是它們在記錄中的伴隨屬性。 – deco20
你的謂詞'@「的名字像%@」,place'找到所有「名字」(或多或少)等於「place」的對象,那麼爲什麼你驚訝所有顯示的名字是相同的呢? –