【发布时间】:2012-08-05 02:20:16
【问题描述】:
我正在尝试将视图的内容保存到 PDF 文件中。您看到的代码位于从 NSView 继承的类中:
- (IBAction) savePDF: (id) sender
{
__block NSSavePanel* panel=[NSSavePanel savePanel];
[panel setAllowedFileTypes: [NSArray arrayWithObject: @"pdf"]];
[panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result)
{
if(result==NSOKButton)
{
NSCAssert(panel!=nil,@"panel is nil");
NSData* data=[self dataWithPDFInsideRect: [self bounds]];
NSError* error;
BOOL successful=[data writeToURL: [panel URL] options: 0 error: &error];
if(!successful)
{
NSAlert* alert=[NSAlert alertWithError: error];
[alert runModal];
}
}
}];
panel=nil;
}
该方法由菜单触发。
问题是断言失败:
NSCAssert(panel!=nil,@"panel is nil");
即使我将 NSSavePanel 指针声明为 __block。为什么?
【问题讨论】:
标签: objective-c cocoa osx-lion nssavepanel