0

I'm attempting to write a SplitView control program in which pressing a table cell in the masterViewController causes an associated web page to load in the detail view controller. I have the following method in the detail view controller that I can confirm is getting called and is receiving the correct input:

  -(void)masterAction:(id)sender  {

    NSString *http = @"http://";
    http = [http stringByAppendingString:sender];
    _urlString = http;


    NSURL *url= [NSURL URLWithString:_urlString];
    [self.web loadRequest:[NSURLRequest requestWithURL:url]];

     }

However, nothing is loading. Any ideas why this might be? The only way I've been able to get anything at all to load is to insert something similar to the following in my viewDidLoad method:

NSURL *url= [NSURL URLWithString:@"http://www.google.com];
[self.web loadRequest:[NSURLRequest requestWithURL:url]];

The method is being called using:

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *thread = [self.issueData objectForKey:@"responseData"];
    NSDictionary *feed = [thread objectForKey:@"feed"];


    NSArray *entries = [feed objectForKey:@"entries"];
    NSDictionary *posts = entries[indexPath.row];

    NSString *urlString = [posts objectForKey:@"link"];
    NSArray *split = [urlString componentsSeparatedByString:@"url=http://"];

    NSString   *url = [split objectAtIndex:1];

    [self.delegate masterAction:url];

}
planner15
  • 53
  • 8
  • Why are you appending `sender` to `http://`? What is `sender`, a button? – rmaddy Feb 16 '15 at 19:15
  • Did you initialise `self.web`? – Gabriel Tomitsuka Feb 16 '15 at 19:22
  • Sender is a string in the form 'www.google.com.' I declared web in my header file as such: '@property (weak, atomic) IBOutlet UIWebView *web;' – planner15 Feb 16 '15 at 19:28
  • If `sender` is an `NSString`, why is its type `id` and why is it named `sender`? And why it the method an action? – rmaddy Feb 16 '15 at 19:50
  • -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *thread = [self.issueData objectForKey:@"responseData"]; NSDictionary *feed = [thread objectForKey:@"feed"]; NSArray *entries = [feed objectForKey:@"entries"]; NSDictionary *posts = entries[indexPath.row]; NSString *urlString = [posts objectForKey:@"link"]; NSArray *split = [urlString componentsSeparatedByString:@"url=http://"]; NSString *url = [split objectAtIndex:1]; [self.delegate masterAction:url]; } – planner15 Feb 16 '15 at 20:11
  • @planner15 Don't post code in the comments. Update your question with relevant details. – rmaddy Feb 16 '15 at 20:25

2 Answers2

0

I duplicated this code in a test project and the only piece of code where something can go wrong is if you are forgetting to put www. after the http:// before the domain name. Trying changing your masterAction method to the one below:

- (void) masterAction: (id) sender
{
    if (![sender isKindOfClass:[NSString class]]) return;
    NSString *http = @"http://www.";
    NSString *urlString = [http stringByAppendingString:sender];
    NSURL *url = [NSURL URLWithString:urlString];
    [self.web loadRequest:[NSURLRequest requestWithURL:url]];
}

If this is not the issue and the string being sent to the method contains the www. try setting the delegate of the UIWebView to see if any error is thrown when loading the request.

SierraMike
  • 1,539
  • 1
  • 11
  • 18
0

set the delegate of webview.

and try this.

NSString *myUrl = @"http://www.YourWebSite.com";
NSURL *webUrl = [NSURL URLWithString:myUrl];
[webObj loadRequest:[NSURLRequest requestWithURL:webUrl]];
Ankit Kargathra
  • 309
  • 3
  • 16