0

我正在尝试编写一个 SplitView 控制程序,其中按下 masterViewController 中的表格单元格会导致关联的网页加载到详细视图控制器中。我在详细视图控制器中有以下方法,我可以确认它正在被调用并且正在接收正确的输入:

  -(void)masterAction:(id)sender  {

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


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

     }

但是,没有加载任何内容。任何想法为什么会这样?我能够加载任何内容的唯一方法是在我的 viewDidLoad 方法中插入类似于以下内容的内容:

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

正在使用以下方法调用该方法:

-(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];

}
4

2 回答 2

0

我在一个测试项目中复制了这段代码,唯一可能出错的代码是如果你忘记输入 www. 在域名之前的 http:// 之后。尝试将您的 masterAction 方法更改为以下方法:

- (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]];
}

如果这不是问题并且发送到该方法的字符串包含 www. 尝试设置 UIWebView 的委托以查看加载请求时是否引发任何错误。

于 2015-02-16T21:46:31.860 回答
0

设置 webview 的委托。

试试这个。

NSString *myUrl = @"http://www.YourWebSite.com";
NSURL *webUrl = [NSURL URLWithString:myUrl];
[webObj loadRequest:[NSURLRequest requestWithURL:webUrl]];
于 2015-02-17T05:26:05.540 回答