0

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]
jeanpaul62
  • 9,451
  • 13
  • 54
  • 94

2 Answers2

0

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

jatoben
  • 3,079
  • 15
  • 12
  • Well actually here it's not exactly the parent, because: 1) i did a `[tabViewItem setView:webView]` so `tabViewItem` is not the superview of my webview, and 2) superview returns a NSView object and what I want is a NSTabViewItem. – jeanpaul62 May 16 '14 at 06:05
0

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];
Jody Hagins
  • 27,943
  • 6
  • 58
  • 87