我浏览了很多帖子,但仍然不确定如何解决这个问题。希望有人可以提供帮助。
它一直有效,直到到达最后一个数据源方法 cellForRow。那时我可以为每个部分获得正确的 NSSet,但无序。对关系属性的内省如何对行起作用?
在 cellForRow 中使用字符串文字我确实在每个部分中获得了正确的行数,但显然与那里的托管对象没有连接。
如何填充 NSSet 关系中的行?赞赏所有见解
类别<<--->>Person
cName ---------- pName
关系
人 ---------- 类别
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[self.fetchedResultsController fetchedObjects] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Category* cat = [[self.fetchedResultsController fetchedObjects] objectAtIndex:section];
return [[cat people] count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Category* cat = [[self.fetchedResultsController fetchedObjects] objectAtIndex:section];
NSNumber *rowCount = [NSNumber numberWithUnsignedInteger:[[cat people] count]];
return cat.cName;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *mo = [[fetchedResultsController fetchedObjects] objectAtIndex:index.row]];
// returns the correct set but unordered, possibly work with this to populate the rows?
//NSSet *theSet = [[NSSet alloc] initWithSet: [mo valueForKeyPath:@"people.pName"]];
// doesn't work
// cell.textLabel.text = [NSString stringWithFormat:@"%@",[mo valueForKeyPath:@"people.pName"]];
cell.textLabel.text = @"something";
return cell;
}