Using notifications: let's say where you catch the key stroke, you have an NSString object containing some identifier to identify the desired WebView (for example, @"1" or @"2" , etc.), and each web view has viewID property. Therefore, when you get the key touch, you should add:
[[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeMyActiveWebView" object:newViewID
Somewhere where your webview is initialized (e.g. -awakeFromNib or -init), you add this code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchViewNotification:) name:@"ChangeMyActiveWebView" object:nil
Then we implement the -switchViewNotification :: method
- (void)switchViewNotification:(NSNotification *)aNotification { NSString *newViewID=[aNotification object]; if([self.viewID isEqualToString:newViewID]) {
The final part: you need to remove the observer when the web view disappears, so add this to your -dealloc method:
[[NSNotificationCenter defaultCenter]removeObserver:self];
That should do it.
source share