- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 coredata 中有 2 个表:
@interface Section (CoreDataProperties)
@property (nullable, nonatomic, retain) NSString *button;
@property (nullable, nonatomic, retain) NSString *header;
@property (nullable, nonatomic, retain) NSString *position;
@property (nullable, nonatomic, retain) NSString *projectid;
@property (nullable, nonatomic, retain) NSNumber *scroll;
@property (nullable, nonatomic, retain) NSString *source;
@property (nullable, nonatomic, retain) NSString *status;
@property (nullable, nonatomic, retain) NSString *subheader;
@property (nullable, nonatomic, retain) NSString *tag;
@property (nullable, nonatomic, retain) NSString *userid;
@property (nullable, nonatomic, retain) NSSet<Cell *> *cells;
@end
@interface Section (CoreDataGeneratedAccessors)
- (void)addCellsObject:(Cell *)value;
- (void)removeCellsObject:(Cell *)value;
- (void)addCells:(NSSet<Cell *> *)values with:(NSDictionary *) inputData;
- (void)removeCells:(NSSet<Cell *> *)values;
@end
@interface Cell (CoreDataProperties)
@property (nullable, nonatomic, retain) NSString *cellid;
@property (nullable, nonatomic, retain) NSString *overpic;
@property (nullable, nonatomic, retain) NSString *pictitle;
@property (nullable, nonatomic, retain) NSString *position;
@property (nullable, nonatomic, retain) NSString *subpic;
@property (nullable, nonatomic, retain) NSString *subtitle;
@property (nullable, nonatomic, retain) NSString *title;
@property (nullable, nonatomic, retain) Section *section;
@end
子记录的自定义保存:
- (void)addCells:(NSSet<Cell *> *)values with:(NSDictionary *) inputData{
[values setValue:[inputData objectForKey:@"overpic"] forKey:@"overpic"];
[values setValue:[inputData objectForKey:@"pictitle"] forKey:@"pictitle"];
[values setValue:[inputData objectForKey:@"position"] forKey:@"position"];
[values setValue:[inputData objectForKey:@"subpic"] forKey:@"subpic"];
[values setValue:[inputData objectForKey:@"subtitle"] forKey:@"subtitle"];
[values setValue:[inputData objectForKey:@"title"] forKey:@"title"];
}
这里调用自定义保存:
[tempSection addCells:(NSSet *)[Cell MR_createEntity] with:myDictionary];
我保存:
[localContext MR_saveToPersistentStoreAndWait];
localContext is at the top of the this method:
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
然后我通过以下方式获取记录:
NSArray *sections = [Section MR_findAll];
列出上下文:
for (int j=0; j<sections.count; j++) {
mySection = [sections objectAtIndex:j];
MLog(@"sections header %@",mySection.header);
MLog(@"sections button %@",mySection.button);
MLog(@"sections position %@",mySection.position);
MLog(@"sections projectid %@",mySection.projectid);
MLog(@"sections scroll %@",mySection.scroll);
MLog(@"sections source %@",mySection.source);
MLog(@"sections status %@",mySection.status);
MLog(@"sections subheader %@",mySection.subheader);
MLog(@"sections tag %@",mySection.tag);
MLog(@"sections userid %@",mySection.userid);
MLog(@"cell count: %lu", mySection.cells.count);
}
问题是单元格计数为 0。(mySection.cells 的实际输出如下)
我在另一个提取中列出了单元格,这些单元格就在那里。
关系是一个部分到多个单元格。
我注意到在 CoreData 中您没有设置连接字段,所以我假设 CoreData 负责将子项连接到父项。
我正在使用 MagicalRecord,但在文档中看不到任何帮助。
我可以从任一表中获取所有记录,但它们之间没有任何联系。我不知道自定义添加子字段是否有问题,但我不知道如何在子记录中添加 NSSet 字段,或者我是否应该这样做。
如果我只捕获一个部分:
Section *onlyOne = [Section MR_findFirstByAttribute:@"position" withValue:@"02" inContext:localContext];
MLog(@"section cells %@",onlyOne.cells);
我明白了:
section cells Relationship 'cells' on managed object (0x7f8c1af282c0) <Section: 0x7f8c1af282c0> (entity: Section; id: 0xd000000000740000 <x-coredata://2084C475-532F-4BBB-86A3-FFFBE63A0BB3/Section/p29> ; data: {
button = Change;
cells = (
);
header = "Tech News";
position = 02;
projectid = "";
scroll = 1;
source = "source here";
status = 2;
subheader = "subHeader Here for Tech News";
tag = 2;
userid = nil;
}) with objects {(
)}
^^ 这具有部分数据和一个看起来是空的“带有对象”,而不是具有属于该部分的单元格。
如何将单元格连接到它们的部分?
最佳答案
在 addCellsObject: 中,您的代码应如下所示:
- (void)addCellsObject:(Cell *)value
{
NSMutableSet* set = [self mutableSetValueForKey:@"cells"];
[set addObject:value];
}
因此,您使用现有 Cell 调用该方法,该方法将 Cell 添加到单元格集(Section 的属性)。不确定您在其他方法中试图实现什么,但您至少必须将单元格添加到单元格集中。
关于ios - 从 coredata 返回 parent 和 child 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37559339/
按照我目前安排代码的方式,下一行将为各种托管对象上下文运行。一些获取的实体将具有“complededDate”,而其他实体将没有“completedDate”属性。 let task = retrie
我在 import CoreData 的应用程序委托(delegate)中遇到此错误。据我所知,这是因为我将一个项目命名为 coreData。但是我更改了项目的名称,然后将其删除,并且删除了 /Lib
我想将记录保存在数组中并从 CoreData 中删除它们。我尝试过使用 NSCopying 但似乎 copyWithZone 不适用于 NSManagedObject。我真的很困惑,任何帮助将不胜感激
有时我的项目中很少会出现错误(比如每第 100 个请求)。我的一些 CoreData 的请求有 data:我无法使用该数据。我真的不明白为什么会发生这种情况以及如何防止这种行为。 错误数据输出示例:
如果您使用 Xcode 创建一个新项目并告诉它在您创建项目时创建一个 CoreData 模板,则您不需要 #import 在使用 ManagedObjects 的类中。 我已经将 Core Data
我对 SQLCipher 数据库加密和 CoreData 有疑问:当我将持久存储协调器与 SQLCipher 一起使用时,它总是在第一次应用程序重新启动后因一对多关系故障而崩溃。因此,当我第一次启动该
我有一个想要添加 iCloud 支持的应用程序。此应用程序从服务器加载数据,并将数据存储在 CoreData 中,以便 NSFetchedResultsController可以管理UITableVie
我正在从 coredata 表 STUDENT 中获取数据,并使用 Array 在 tableview 中显示所有学生姓名。在选择任何一个学生姓名后(点击 tableViewCell),它会从另一个表
我在构建过程中收到以下错误。 “API 滥用:尝试序列化非拥有协调器上的存储访问(PSC = 0x7fb5ae208890,存储 PSC = 0x0)CoreData 为什么我的应用程序会出现 Cor
当将 iOS 6.0.1 上的 Core Data 托管对象上下文保存到 SQLite 存储时,我遇到了一个奇怪的“CoreData 不支持持久的跨存储关系”异常。它涉及模型中 Quotes 和 Ab
我的应用程序有两个选项卡栏...每个选项卡栏都将用户带到一个向他显示项目列表的 TableView Controller 。第一个 View 允许用户在数据库中记录条目。另一个选项卡/ View 从数
Objective-C (OC) 中使用 Core Data 是iOS应用开发中管理模型层对象的一种有效工具。Core Data 使用 ORM (对象关系映射) 技术来抽象化和管理数据。这不仅可以节省
我有一个名为visitDate的coredata属性 我想使用单独的选择器相互独立地设置日期和时间。 我意识到,当我设置时间时,我需要获取visitDate的现有日期、月份和年份,但只从NSDateP
我有这个代码示例演示如何更新核心数据中的对象,但是我遇到了一个小问题: // Retrieve the context if (managedObjectContext == nil) { m
我在 CoreData 中有一个包含整数值的列。在从中检索结果时,我希望将列值减去一个数字。 类似于:columnValue - someNumber(此数字由用户输入) 我知道我可能必须为此使用 N
有没有办法将 CoreData 模型文件(即实体描述:*.xcdatamodeld)导出到另一个项目。因为重新创建所有实体很无聊:-) 最佳答案 是的,只需将模型文件本身添加/复制到新项目中,就像任何
我使用核心数据编写了 iPhone 应用程序。当我在模拟器中运行应用程序时,它崩溃并出现以下错误: 2010-02-12 17:24:22.359 CrData[46122:4503] Unresol
我是 CoreData 的新手,在我的 iPhone 应用程序中,我想知道如何保存一些文本,然后将其重新加载。但诀窍是,当 UIDatePicker 中的日期与我相同时加载它。像日历一样保存它。 更新
我正在寻找在 CoreData 中编写一些基本查询的方法,但文档中没有示例。以下是我的查询: 我有一个费用对象,它有一个费用金额字段。 费用可以链接到 ExpenseCategory 对象。 Expe
我在标题中使用“单例”一词时可能存在术语不正确的情况。我现在正在寻找一种好的技术。我有一个名为 user 的实体,它存储用户登录的数据,例如用于发出服务器请求的 session key 。我只希望这些
我是一名优秀的程序员,十分优秀!