我正在尝试打印NSTableView通过自定义填充的数据NSView。当用户发出打印命令时,NSView包含的自定义NSTableView按预期显示在打印面板中
我遇到的问题如下:如果用户更改打印面板中的任何设置,填充的数据将NSTableView被空白。如果用户单击打印,也会发生同样的事情。我的问题:当用户与打印面板交互时,如何使数据不消失?
附加信息: (1) 中的标签NSView按预期显示,(2) 如果我绕过打印面板,按预期发出打印[printOp setShowsPrintPanel:NO]; [printOp runOperation];中的数据NSTableView。
推测:我正在更新我的程序以使用自动引用计数 (ARC)。似乎指向数据的指针被提前释放了,这样当用户与打印面板交互时,数据不再可供NSView; 但我无法确定发生的位置(据我所知,在首次显示打印面板之后,我的代码没有被访问)。
任何帮助将不胜感激。谢谢你。附件是一些帮助诊断的代码。
从 MyDocument.m(的子类NSDocument)开始打印操作的代码:
-(NSPrintOperation *)printOperationWithSettings:(NSDictionary *)ps error:(NSError **)e
{
DeductionTablePrintViewController *pvc = [[DeductionTablePrintViewController alloc] initWithScopeDeduction:deduction andHelper:helper andDeductionController:self];
NSPrintInfo *printInfo = [self printInfo];
NSRect viewFrame = [[pvc view] frame];
viewFrame.size.width = [printInfo imageablePageBounds].size.width;
[[pvc view] setFrame:viewFrame];
NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:[pvc view] printInfo:printInfo];
return printOp;
}
DeductionTablePrintViewController是NSViewController严格用于打印的子类。有对应的xib文件。从DeductionTablePrintViewController.h(连接到xib:
IBOutlet DeductionTable *deductionTable;
现在为DeductionTablePrintViewController.m:
-(id)initWithScopeDeduction:(ScopeDeduction *)aDeduction andHelper:(DeductionHelper *)aHelper andDeductionController:(MyDocument *)aDeductionController
{
self = [super initWithNibName:@"DeductionTablePrintView" bundle:nil];
if (self) {
// Set deduction
deduction = [aDeduction copy]; // Deep copy
deductionController = aDeductionController; // MyDocument
[[(DeductionTablePrintView *)[self view] deductionTable] setDeduction:deduction];
}
return self;
}
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)row
{
id objectValue = nil;
// objectValue is calculated here
... ... ...
return objectValue;
}
这是“之前”屏幕截图,打印预览中的表格数据(以及从这里开始的打印输出)被正确填充。
这是“之后”的屏幕截图,打印预览中的表格数据(以及从这里开始的打印输出)在单击“页面:从到”单选按钮后消失了。