Ios 加载UIWebView时出现问题

Ios 加载UIWebView时出现问题,ios,objective-c,uiwebview,uisplitview,Ios,Objective C,Uiwebview,Uisplitview,我正在尝试编写一个SplitView控制程序,在该程序中,按下masterViewController中的表格单元格会导致在detail view控制器中加载关联的网页。在详图视图控制器中,我可以确认调用了以下方法,并且收到了正确的输入: -(void)masterAction:(id)sender { NSString *http = @"http://"; http = [http stringByAppendingString:sender]; _urlSt

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

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

为什么要在
http://
中附加
发送者
?什么是
sender
,一个按钮?您是否初始化了
self.web
?sender是一个格式为“www.google.com”的字符串。我在头文件中声明了web:“@property(弱,原子)ibuiwebview*web;”如果
sender
是一个
NSString
,为什么它的类型是
id
,为什么它被命名为
sender
?为什么它会将方法作为一个动作?-(void)tableView:(UITableView*)tableView取消了RowAtIndexPath:(NSIndexPath*)indexPath{NSDictionary*线程=[self.issueData objectForKey:@“responseData”];NSDictionary*提要=[thread objectForKey:@“提要”];NSArray*条目=[feed objectForKey:@“entries”];NSDictionary*posts=entries[indexath.row];NSString*urlString=[posts objectForKey:@“link”];NSArray*split=[urlString ComponentSeparatedByString:@“url=http://”];NSString*url=[split objectAtIndex:1];[self.delegate主操作:url];}