WebView Showing current url issue.

Discussion in 'Mac Programming' started by DavidBlack, Jun 6, 2013.

  1. DavidBlack macrumors 6502a


    Jan 27, 2013
    Somewhere In Apple's HQ ;)
    Ok guys I want my webview to show the current url of the page it's on. So I went to:
    To find out how to do it. I set up my webview to load apple.com when it's finish launching and I placed this into the - (void)applicationDidFinishLaunching method. it works fine it loads apple.com. But I want to show the current url as a string in a NSTextField so I connected a Outlet to a NSTextField and named it urltext. Then I used the method from apple's web site:
    - (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
        // Only report feedback for the main frame.
        if (frame == [sender mainFrame]){
            NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
            [self.urltext setStringValue:url];
    But some how it's not working can anyone help me? :)
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Break It Down.

    1. Confirm the method is being called at all.
    Use either a breakpoint in the debugger or an NSLog to confirm this.

    2. Confirm the method is being called at the right points.
    Same as #1, but observe exactly when the breakpoint triggers or the NSLog output appears.

    3. Confirm the body of the 'if' is being executed.
    Same as #1, but move the breakpoint or the NSLog into the { } block of the 'if' statement, and confirm it happens when it should.

    4. Confirm that the local variable 'url' has a non-nil value.
    Again, a breakpoint or NSLog can show this.

    5. Confirm that self.urltext has a non-nil value.

    6. If 'url' and self.urltext are both non-nil, then exactly what is the value of 'url'?
    NSLog it.

    7. If one of 'url' or self.urltext is nil, figure out why.
    If the url is nil and urltext isn't, then does setting a literal string to urltext work? If the url is non-nil and urltext is nil, then go back and figure out why urltext is nil (possibly related to loading a nib or assigning an outlet).

    Continue breaking the problem into separately observable parts, and confirming that what you expect to have at each step (a non-nil 'url' string, a non-nil urltext) is what you actually have.

    At every step, you should ask yourself two questions:
    1) What should I expect here?
    2) What do I actually get here?

    Debugging is the process of breaking down a problem, figuring out what to expect, and then confirming that you actually get what you expect. If you don't know what to expect, then you don't understand the code. If you don't get what you expect, then figure out why not.

    If you can't break things down into separately observable parts, then you should learn to do that. Debugging is a fundamental skill, as is breaking things down in general. Programming itself is the process of breaking problems down into smaller parts you can solve.
  3. gwelmarten macrumors 6502

    Jan 17, 2011
    I'm having the same problem right now. Did you ever fix this, and if so how?

Share This Page