问题
I would like to display the urls from a table view in a QLPreviewPanel but i got this error:
[QL] QLError(): -[QLPreviewPanel reloadData] called while the panel has no controller - Fix this or this will raise soon.
My table controller already conform to this two protocols : QLPreviewPanelDataSource, QLPreviewPanelDelegate.
How can i set the controller of [QLPreviewPanel sharedPreviewPanel]
as my table controller?
- (void)didPressSpacebarForTableView:(NSTableView *)tableView {
NSLog(@"Spacebar clicked");
if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
[[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
} else {
[[QLPreviewPanel sharedPreviewPanel] reloadData];
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
}
}
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel {
return [[(PasteboardItem *)[[_arrayController arrangedObjects] objectAtIndex:[_tableView selectedRow]] filenames] count];
}
- (id<QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index {
NSString *path = [(PasteboardItem *)[[_arrayController arrangedObjects] objectAtIndex:[_tableView selectedRow]] filenames][index];
NSURL *url = [NSURL fileURLWithPath:path];
return url;
}
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel *)panel {
return YES;
}
-(void)beginPreviewPanelControl:(QLPreviewPanel *)panel {
panel.dataSource = self;
panel.delegate = self;
}
- (void)endPreviewPanelControl:(QLPreviewPanel *)panel {
panel.dataSource = nil;
panel.delegate = nil;
}
回答1:
I found the solution here: QuickLook consumer as a delegate from an NSViewController. In my case i need these 3 lines of code in the panel controller (NSWindowController) where i have the instance of my table view controller.
- (void)awakeFromNib {
NSResponder * aNextResponder = [self nextResponder];
[self setNextResponder:_tableController];
[_tableController setNextResponder:aNextResponder];
}
来源:https://stackoverflow.com/questions/28399080/qlpreviewpanel-in-tableview-with-issue-has-no-controller