views:

69

answers:

2

Hi!

Another problem for me with my application is a simple procedure. I want to have a button which, if you press, opens the link associated with the article in question. I have followed instructions that i understand, but I am having trouble understanding why the link will not work.

- (IBAction)link:(id)sender {
WebViewController *view = [[WebViewController alloc] initWithNibName:@"WebViewController" 
                                                              bundle:nil];
[[self navigationController]pushViewController:view 
                                      animated:YES];
NSString *urlAddress = [item objectForKey:@"link"];
NSLog(@"urlad = %@", urlAddress);
NSURL *url = [[NSURL alloc] initWithString: urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSLog(@"url = %@", url);
[[view webView] loadRequest:request];

[urlAddress release];
[url release];
[view release];}

I have tried investigating this further, but with no luck (The NSLogs). I can tell that the "link" is getting into the urlAddress string, but the url NSURL will not accept the string conversion. It is most irritating.

If anyone could help, i would be most grateful.

A: 

Did you remember to connect the method to the button in Interface Builder?

Alexsander Akers
Yes, the button is linked (Touch up inside) to the file's owner link:The url always isurl = (null)in the debugger console.Thanks for the suggestion.
SKato
A: 

What is the console output for the first NSLog?

Hila's Master
The first console output (urlAddress) was the address I parsed from the rss feed, which is telling me that the parse section is working and I am able to place that link into a string. However, the 2nd output (url) comes up as (null) which is puzzling.
SKato
I believe your address is bad at first, containing a bad character or something like that. Try using a static address and tell me what happens.
Hila's Master
Ok, sorry for the late response, but I put the address in an NSString and used that in the code I developed.Instead of:NSString *urlAddress = [item objectForKey:@"link"];I did:NSString *urlAddress = @"http://www.yahoo.com";And the website opened up normally. No errors or excess waiting.
SKato
Just tried something different. I was having a similar problem with the DateFormatter, but then i came across advice i hadnt considered: trimming. So i changed the first part to this:NSString *urlAddress = [[item objectForKey:@"link"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];And now the url is acknowledged by the program!...but then it crashes when it tries to open the website. :(
SKato