QLPreviewPanel in tableview with issue: “has no controller”

半城伤御伤魂 提交于 2019-12-24 04:51:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!