uiwebview

Tap Detecting Window and Two View Controllers


I'm rather new to iOS development and for my first real app I'm using a TapDetectingWindow to detect touches on a UIWebView (exactly as detailed on http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way).

I used it in one View Controller as suggested with a reference in the header file and the following in the implementation file;

- (void)viewDidLoad {
        [super viewDidLoad];
        mWindow = (TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0];
        mWindow.viewToObserve = igWeb;
        mWindow.controllerThatObserves = self;

- (void)userDidTapWebView:(NSArray *)tapPoint {


    }

It worked perfectly.

Now the problem is that I would like to use the TapDetectingWindow in a second View Controller.

I copied the same code from the first view controller (only changing the name of the viewToObserve).

Now, when I run the app. The Tap Detecting window works fine in the first ViewController, then works fine when you go to the second View Controller but when you go back to the first view controller its broken until the view gets loaded again.

Please help.


Solution

  • try something like

    -(void)viewWillAppear:(BOOL)animated
    {
        mWindow.viewToObserve = igWeb;
        mWindow.controllerThatObserves = self;
        [super viewWillAppear:animated];
    }