Hugo Oshiro
Hugo Oshiro

Reputation: 380

Why code is not being executed?

I have the following method in a class that extends WebView

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"WEBVIEW - Start Load");

    static BOOL isFirstLaunch = YES;

    if (isFirstLaunch) {
        isFirstLaunch = NO;

    } else {
        [webView stringByEvaluatingJavaScriptFromString:@"localStorage.states = '[{},{\"name\":\"Dashboard\"}]'"];
    }
      // webView connected
    webviewTimeout = [NSTimer scheduledTimerWithTimeInterval:kWebViewLoadTimeOut target:self selector:@selector(webViewTimeout) userInfo:nil repeats:NO];
}

the static declaration plus the if else is jumped when program is executing. I notice this when in Xcode debugger. I can't see anything wrong with my code. I though it could be due to static BOOL variable declaration inside the method, I declared it out of any blocks in the .m file. but the if else still not being execute. I also tried to put the code in a ViewController class before loading my WebView, but the code mentioned still not being executed. What I'm missing here?

To be clearer: I notice that code is not being executed with Xcode Debugger. I put a breakpoint in the method beginning ,in NSLog, if I put any breakpoint in any part that is inside if else or in the static variable declaration, seems to ignore it, and no break is done.

Thanks in advance.

Upvotes: 0

Views: 107

Answers (2)

user1118321
user1118321

Reputation: 26325

Compiler optimizations can sometimes confuse the debugger. They can rearrange instructions or even remove code. Turning them off can make it easier to step through the code.

Upvotes: 1

Mike
Mike

Reputation: 9835

Are you sure you have done the following:

// set yourself as the delegate
webView.delegate = self;

// begin loading
[webView loadRequest:[NSURLRequest requestWithURL:@"http://www.someURLHere.com"]];

Upvotes: 0

Related Questions