I'm working on a master detail app and I'm having a problem reloading my webview after a selection is made in the tableView. I'm inclined to think the problem is something very simple with my NSURL assignment. Below is the relavent code.
this function is in my masterview;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UGStory *detailStory = [_ugFeed.stories objectAtIndex:indexPath.row];
[_detailViewController displayMaster:detailStory.url];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
this one is in the detailview
- (void) displayMaster:(NSURL *)urlToLoad
{
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlToLoad];
[_webView loadRequest:requestObj];
}
and this is where the NSURL is being set
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (_read == YES)
{
if ([elementName isEqualToString:@"title"]) {
UGStory* temp = [_stories objectAtIndex:_i];
temp.title = _currentTag;
}
if ([elementName isEqualToString:@"link"]) {
UGStory* temp = [_stories objectAtIndex:_i];
temp.url = [NSURL URLWithString:_currentTag];
_read = NO;
_i++;
}
}
_currentTag = nil;
return;
}
I suspect that my assignment of temp.url is not working as expected. I've printed the _currentTag using NSLog and it hold the correct value when it occurs.
url is declared as a strong nonatomic property. When I execute this all of these functions are called when I would expect them to, but after the execution of the displayMaster function the contents of the WebView does not change.
EDIT: I've deleted some of my OP because I have clearly identified which line of code is causing the problem. It is the URL assignment in didEndElement, URLWithString is returning nil.
if ([elementName isEqualToString:@"link"]) {
NSLog(@"urlString = %@", _currentTag);
temp.url = [NSURL URLWithString:_currentTag];
NSLog(@"url = %@, %@", temp.url, [temp.url absoluteString]);
_read = NO;
_i++;
}
The output in my log looks like the following for every object in my array.
2012-01-07 20:14:22.971 MusicNews[1162:f803] urlString = http://www.ultimate-guitar.com/news/general_music_news/30_seconds_to_mars_no_plans_to_split.html 2012-01-07 20:14:22.982 MusicNews[1162:f803] url = (null), (null) 2012-01-07 20:14:22.982 MusicNews[1162:f803] urlString = http://www.ultimate-guitar.com/news/upcoming_releases/kiss_two_days_from_finishing_new_album.html 2012-01-07 20:14:22.983 MusicNews[1162:f803] url = (null), (null)
Can anyone explain why URLWithString isn't working here?