使用通知:說,你抓住你有一些含有ID來識別期望的web視圖(例如@"1"
或@"2"
等)一個NSString對象的關鍵筆劃,並且每幅視圖具有viewID
屬性。那麼,您收到的擊鍵,你要補充:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ChangeMyActiveWebView"
object:newViewID // <- contains string to identify the desired web view
];
的地方在那裏你的Web視圖進行初始化(例如-awakeFromNib或-init),則添加以下代碼:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(switchViewNotification:)
name:@"ChangeMyActiveWebView"
object:nil // Means any object
];
然後實施-switchViewNotification:方法:
- (void)switchViewNotification:(NSNotification *)aNotification {
NSString *newViewID=[aNotification object];
if([self.viewID isEqualToString:newViewID])
{
// show this web view
}
else
{
// hide this web view
}
}
最後一塊:你需要在Web視圖消失刪除觀察者,所以將它添加到您的-dealloc
方法:
[[NSNotificationCenter defaultCenter]removeObserver:self];
這應該做到這一點。
對不起,但你的問題不夠具體。你基本上是問如何顯示或隱藏視圖?正確的方向是做一些關於AppKit的閱讀。 https://developer.apple.com/library/mac/navigation/#section=Resource%20Types&topic=Getting%20Started –
例如,當WebView捕獲一個CMD + 1時,我希望能夠調用其他方法WebViews隱藏它們。這就是我想要做的。對不起,如此模糊,謝謝你的迴應! – TomShreds