Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 6, 2013, 07:21 PM   #1
DavidBlack
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
WebView Showing current url issue.

Ok guys I want my webview to show the current url of the page it's on. So I went to:
https://developer.apple.com/library/...onChanges.html
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:
Code:
- (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?
DavidBlack is offline   0 Reply With Quote
Old Jun 6, 2013, 07:41 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
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.
Same.

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.
chown33 is offline   0 Reply With Quote
Old Dec 11, 2013, 03:28 PM   #3
gwelmarten
macrumors 6502
 
Join Date: Jan 2011
Location: England!
Quote:
Originally Posted by DavidBlack View Post
Ok guys I want my webview to show the current url of the page it's on. So I went to:
https://developer.apple.com/library/...onChanges.html
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:
Code:
- (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?
I'm having the same problem right now. Did you ever fix this, and if so how?
gwelmarten is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
YouTube and Webview issue DavidBlack Mac Programming 1 Feb 4, 2014 11:50 AM
Current App store issue Beecker MacBook Pro 0 Dec 10, 2013 03:04 PM
Using a Hyphen In A URL vs. Using A URL with .us TLD steiney Web Design and Development 32 Jul 12, 2013 02:30 PM
Issue: iMessage showing telephone number for contact stored jaysen iOS 6 5 Jun 5, 2013 06:34 AM
WebView - change scalePagesToFit for certain URL? tomgoo iPhone/iPad Programming 5 Jun 30, 2012 11:00 AM

Forum Jump

All times are GMT -5. The time now is 01:28 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC