def*_*ott 1 macos core-data nstableview nsarraycontroller cocoa-bindings
我有一个配置了模式'Entity'的NSArrayController,它包含所选类型为'Person'和'Prepares Content'的Core-Data-Entities.所有其他属性都是默认属性.正如所料,当我创建新的Person-entities时(通过按钮单击),此arraycontroller更新其arrangeObjects:
-(IBAction)addEntity:(id)sender{
Person* new = [NSEntityDescription insertNewObjectForEntityForName:@"Person"
inManagedObjectContext:[self managedObjectContext]];
new.text = @"text";
new.date = [NSDate date];
}
Run Code Online (Sandbox Code Playgroud)
我已将基于视图的NSTableView的内容绑定到此arrayController的'arrangeObjects'属性,以显示Persons.在一列中,我有一个可编辑的(但默认情况下是默认的)NSTextField绑定到TableCellView的'objectValue.text'属性.
如果我编辑表格中的"文本"属性并添加另一个人(当表格单元格仍处于编辑模式时),则表格失去焦点,编辑结束并且新人员显示在表格中.一切都很好看.
但是,如果我想添加另一个人,arrayController不会更新arrangeObjects属性(我发现不再调用arrayController的setContent:).
这是预期的行为吗?
我自己找到了答案.我注意到在编辑表之后没有发送NSManagedObjectContextObjectsDidChangeNotifications(就像之前一样).
这个链接指向了我正确的方向.我按以下方式修改了我的addEntity方法后,一切按预期工作:
-(IBAction)addEintrag:(id)sender {
Person* new = [NSEntityDescription insertNewObjectForEntityForName:@"Person"
inManagedObjectContext:[self managedObjectContext]];
new.name = @"test";
new.datum = [NSDate date];
[self.managedObjectContext processPendingChanges];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1315 次 |
| 最近记录: |