You can get the parent of any NSView by sending it -superview
.
Changing properties of container view
سؤال
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]
لا يوجد حل صحيح
نصائح أخرى
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];