我尝试构建简单的贝塞尔曲线编辑器。型号和代码如下。当我试图删除node.bcpInData或node.bcpOutData 时,只有node.originData被删除,女巫根本没有任何意义。
这是我的模型:
这是删除:方法:
-(void) delete:(id)sender {
[undoManager beginUndoGrouping];
[points willChangeValueForKey:@"arrangedObjects"];
NSMutableArray * nodesToDelete = [NSMutableArray array];
for (TPPointData * pointData in points.selectedObjects) {
NSLog(@"PointData %@", pointData);
NSLog(@"PointData.node = %@", pointData.node);
TPNode * node = pointData.node;
if (pointData == pointData.node.originData) {
//delete everything
[nodesToDelete addObject:pointData.node];
if (pointData.node.bcpInData!=nil) {
NSLog(@"deleting bcpInData: %@", pointData.node.bcpInData);
[moc deleteObject:pointData.node.bcpInData];
pointData.node = nil;
}
if (pointData.node.bcpOutData!=nil) {
NSLog(@"deleting bcpOutData: %@", pointData.node.bcpOutData);
[moc deleteObject:pointData.node.bcpOutData];
pointData.node = nil;
}
NSLog(@"deleting originData: %@", pointData.node.bcpOutData);
[moc deleteObject:pointData];
pointData.node = nil;
} else { //delete just object
[moc deleteObject:pointData];
pointData.node = nil;
}
NSLog(@"node: %@", node);
}
NSMutableArray * contoursToDelete = [NSMutableArray array];
for (TPNode * node in nodesToDelete) {
if (node.contour.nodes.count == 1) {
[contoursToDelete addObject:node.contour];
}
[moc deleteObject:node];
}
for (TPContour * contour in contoursToDelete) {
[moc deleteObject:contour];
}
[points didChangeValueForKey:@"arrangedObjects"];
[undoManager endUndoGrouping];
}
尝试删除原点后列出:
2013-02-03 12:11:34.849 AlwaysSmooth[42786:403] PointData <TPPointData: 0x105c06400> (entity: PointData; id: 0x100133810 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p327> ; data: {
node = "0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328>";
x = "215.5";
y = "550.1667";
})
2013-02-03 12:11:34.850 AlwaysSmooth[42786:403] PointData.node = <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = "0x100133810 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p327>";
prev = "(...not nil..)";
smooth = 1;
type = 2;
})
2013-02-03 12:11:34.851 AlwaysSmooth[42786:403] deleting bcpInData: <TPPointData: 0x100183d70> (entity: PointData; id: 0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326> ; data: {
node = "0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328>";
x = "301.4023";
y = "544.7839";
})
2013-02-03 12:11:34.853 AlwaysSmooth[42786:403] deleting originData: (null)
2013-02-03 12:11:34.854 AlwaysSmooth[42786:403] node: <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = nil;
prev = "(...not nil..)";
smooth = 1;
type = 2;
})
为什么它甚至不尝试删除bcpOutData?originData在删除前为空。删除后,节点对象中仍然存在bcpInData和bcpOutData 。撤消仍然是可能的。
当我尝试仅删除bcpInData或bcpOutData代码时,代码再次仅删除originData:
2013-02-03 12:29:13.526 AlwaysSmooth[42786:403] PointData <TPPointData: 0x100183d70> (entity: PointData; id: 0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326> ; data: {
node = "0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328>";
x = "301.4023";
y = "544.7839";
})
2013-02-03 12:29:13.527 AlwaysSmooth[42786:403] PointData.node = <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = "0x100133810 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p327>";
prev = "(...not nil..)";
smooth = 1;
type = 2;
})
2013-02-03 12:29:13.529 AlwaysSmooth[42786:403] node: <TPNode: 0x105c13250> (entity: Node; id: 0x100133830 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Node/p328> ; data: {
attribute = nil;
bcpIn = "(...not nil..)";
bcpInData = "0x1001337b0 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p326>";
bcpOut = "(...not nil..)";
bcpOutData = "0x100133640 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/PointData/p329>";
contour = "0x1001c8c20 <x-coredata://8E705B64-CB39-4FBD-B296-936E70835DC8/Contour/p282>";
next = "(...not nil..)";
originData = nil;
prev = "(...not nil..)";
smooth = 1;
type = 2;
})
有什么帮助吗?