Pregunta

I have a tabView with let's say 3 tabs, each of the tabViewItems contains a webView. I want to set the title of each tab as the document.title of the HTML page each webView is rendering.

So basically, each NSTabViewItem has a Webview, via [tabViewItem setView:webView];. Now, on the didFinishLoadForFrame delegate of the webviews, I can retrieve the title of the HTML page by doing a NSString *title = [sender stringByEvaluatingJavaScriptFromString:@"document.title"]. I only have access to the sender object, so my question is how can I get the NSTabViewItem containing my sender. In other words, what should I put inside the < >s

[<getNSTabViewItemFromSender:sender> setLabel:title]

No hay solución correcta

Otros consejos

You can get the parent of any NSView by sending it -superview.

Since your web view object is setup as the view for the tab, you can find the tab item that is using your specific web view.

You can implement this as a category on NSTabView (something like this)...

- (NSTabViewItem*)tabViewItemWithView:(NSView*)view {
    for (NSTabViewItem *item in [self tabViewItems]) {
        if (item.view == view) {
            return item;
        }
    }
    return nil;
}

Then, you can set the label for the tab item that contains your web view.

[[tabView tabViewItemWithView:webView] setLabel:label];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top