Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

UIWebView - Trouble displaying current URL in text field

maziarmaziar Posts: 11Registered Users
I'm having problems getting the current URL through a URL request and passing it on to the text field above my web view. I tried logging it and it returns NULL, and the text field remains blank.

This is the delegate I added to my implementation file:

- (void)webViewDidStartLoad:(UIWebView *)webView {
NSURL* url = [webView.request URL];
_webAddress.text = [url absoluteString];
}



And here is my WebViewController.h file:

#import <UIKit/UIKit.h>

@interface WebViewController : UIViewController {

IBOutlet UIWebView *_webView;
IBOutlet UITextField *_webAddress;
IBOutlet UIActivityIndicatorView *activityIndicator;
NSTimer *timer;
NSString *_webURL;
}

@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) IBOutlet UITextField *webAddress;
@property (nonatomic, retain) NSString *webURL;

- (IBAction) doneButton:(id)sender;


@end



And here is my WebViewController.m file:

#import \"WebViewController.h\"


@implementation WebViewController

@synthesize webView = _webView;
@synthesize webAddress = _webAddress;
@synthesize webURL = _webURL;


// Dismiss WebViewController
- (IBAction) doneButton:(id)sender {

[[self parentViewController] dismissModalViewControllerAnimated:YES];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}


- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)webViewDidStartLoad:(UIWebView *)webView {
NSURL* url = [webView.request URL];
_webAddress.text = [url absoluteString];
}

- (void)viewDidLoad
{
[_webView addSubview:activityIndicator];
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_webURL]]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];

[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

- (void)loading {
if (!_webView.loading)
[activityIndicator stopAnimating];

else
[activityIndicator startAnimating];
}

- (void)viewDidUnload
{
_webURL = nil;
_webView = nil;
_webAddress = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}


- (void)dealloc
{
[_webURL release];
[_webView release];
[_webAddress release];
[super dealloc];
}


@end


Does anybody know what I am doing wrong here? Thank you.
Post edited by maziar on

Replies

Sign In or Register to comment.