加载 UIWebView 时出现问题

Problems loading UIWebView

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

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

}

我在测试项目中复制了这段代码,唯一可能出错的代码是您忘记将 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 的委托,看看加载请求时是否抛出任何错误。

设置webview的委托

试试这个。

NSString *myUrl = @"http://www.YourWebSite.com";
NSURL *webUrl = [NSURL URLWithString:myUrl];
[webObj loadRequest:[NSURLRequest requestWithURL:webUrl]];