所以我有表格,我设置了一个名为name
. 第一个表获取 name 的不同值,因为可能有多个相同的名称。下一个表视图打开了这个特定值的副本。
但是,我遇到的问题是从重复项中获取的信息仅来自最新的随附属性。所以他们都指向相同的信息。
这是抓取要放置在表格中的对象的方法。
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;
}
这是将对象放置在表中的方法。
表视图.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
基础的实现,但没有成功。我将不胜感激任何帮助。