我相信答案很简单,但我看不出我做错了什么。
我有两张一对多的桌子:
Entities Users <--> Kind
attributes userName kindName
Relationship hasKinds forUser在我的UITableViewCell中,我已经将TextLabel设置为user,并且尝试将detailTextLabel设置为相关的类型,但它不会允许我。
以下是代码:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{
Users *users = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = users.userName;
cell.detailTextLabel.text = [users.hasKinds.kindName];
}错误是:
在类型为“kindName*”的对象上找不到属性“NSSet”
发布于 2014-03-16 12:25:58
看来,users.hasKinds不是Kind类型,而是NSSet *类型。
检查users.hasKinds属性/方法。
发布于 2014-03-16 12:34:39
在用户和种类之间有一对多或多对多的关系。它的接缝就像用户可以有不止一种。所以,如果你要求一个用户的种类,你会得到一个集与所有的种类。
您现在可以打印一个字符串,其中包含如下所示的所有类型的用户:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{
Users *users = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = users.userName;
NSMutableString *kindsString = [NSMutableString string];
for (Kind *kind in user.hasKinds) {
[kindsString appendString:kind.kindName];
}
cell.detailTextLabel.text = kindsString;
}https://stackoverflow.com/questions/22436648
复制相似问题