【问题标题】:why am I getting only one name out of a CoreData entity?为什么我只能从 CoreData 实体中获得一个名称?
【发布时间】:2013-12-25 19:51:49
【问题描述】:
- (IBAction)done:(id)sender {

    entity = (Entity*)[NSEntityDescription
               insertNewObjectForEntityForName:@"Entity"
               inManagedObjectContext:self.objectContext];

    entity.name = Name;

    for (int i =0 ; i< textfieldarray.count; i++) {

        Timeinday * timeinday = (Timeinday*)[NSEntityDescription
                          insertNewObjectForEntityForName:@"Timeinday"
                          inManagedObjectContext:self.objectContext];

        UITextField *timein = [textfieldarray objectAtIndex:i];


        timeinday.timeinday = timein.text;
        timeinday.name = entity;

    }

    NSError* error;

    [self.objectContext save:&error];
}

当我保存textfieldarray.count大于1时,timeinday.name只记录在一行,其余为空。为什么?

【问题讨论】:

  • 反向关系的基数是多少?

标签: ios objective-c cocoa-touch core-data


【解决方案1】:

您需要在 Entity 对象上为 Timeinday 对象添加 To-Many 关系。像 Entity.times -->> Timeinday 之类的东西。将此设置为与 Timeinday.name 的一对一关系的倒数。

您可能还想为您的对象考虑一些更好的命名约定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 2022-11-05
    • 2013-11-26
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多