Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios webview在设置委派后未显示_Ios_Uiwebview_Delegates - Fatal编程技术网

ios webview在设置委派后未显示

ios webview在设置委派后未显示,ios,uiwebview,delegates,Ios,Uiwebview,Delegates,我正在以编程方式设置webview,在我真正设置委托之前,一切都正常 MainPageViewController.h 下面是我设置委托时页面的外观: 以下是我未设置委托时页面的外观: 唯一的区别是这行代码: [webViewForStories setDelegate:self]; 以下是NSLog的相关输出: 2012-12-26 14:18:40.720 WGGB for iPad[3144:907] webviewForStories delegate is <MainPag

我正在以编程方式设置webview,在我真正设置委托之前,一切都正常

MainPageViewController.h 下面是我设置委托时页面的外观:

以下是我未设置委托时页面的外观:

唯一的区别是这行代码:

[webViewForStories setDelegate:self];
以下是NSLog的相关输出:

2012-12-26 14:18:40.720 WGGB for iPad[3144:907] webviewForStories delegate is <MainPageViewController: 0x1f878cc0>
2012-12-26 14:18:40.721 WGGB for iPad[3144:907] webviewForStories is <UIWebView: 0x1f8838c0; frame = (0 300; 768 1004); layer = <CALayer: 0x1f883920>>

它们似乎都没有被调用。

尝试将委托设置为属性,而不是ivar

[self.webViewForStories setDelegate:self] 

让WebView调用您已实现的委托方法。

我想出来了。。。问题在于这种方法:

// This function allows me to intercept links clicked in a webview and open in
// a navigation window with a back button.
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    NSString *urlString = url.absoluteString;

    NSLog(@"urlstring is %@", urlString);

    // Only catching links without "mobile" in the url (i.e. stories)
    if ([urlString rangeOfString:@"/mobile"].location == NSNotFound && [urlString     rangeOfString:@"facebook"].location == NSNotFound && [urlString rangeOfString:@"facebook"].location == NSNotFound &&[urlString rangeOfString:@"twitter"].location == NSNotFound && [urlString rangeOfString:@"fb://"].location == NSNotFound && [urlString rangeOfString:@"liverail"].location == NSNotFound && [urlString rangeOfString:@"about:blank"].location == NSNotFound) {
        //DetailViewController *detailView = [[DetailViewController alloc] init];
        //[self.navigationController pushViewController:detailView animated:YES];

        return NO;
    } else {
        return YES;
    }
}

if语句在webview的初始加载时被捕获,因此它返回NO,这基本上给了我一个空白屏幕。在允许if语句运行之前,我必须检查这是否是初始加载。

您在web委托方法中做什么?缺少的tableview是问题所在吗?你所说的工作是什么意思,或者唯一的区别是什么?你是否意外地返回了
NO
,实现了
webView:shouldStartLoadWithRequest:navigationType:
?你可以实现
webView:didFailLoadWithError:
,看看它是否给你提供了任何提示。我更新了问题以显示委托方法,尽管没有一个被调用…@carcinbhai,你为什么说我缺少一个tableview?你的“works”屏幕截图中的故事列表,它是webview中显示的html视图吗?或者它是一个UITableView?不幸的是,这给出了相同的结果。仅供参考,我没有ivar,只有属性。是否可以将viewDidLoad代码移动到ViewDidDisplay?我仍然不知道你错在哪里。谢谢。这对我很有帮助。
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"webview finished loading");
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"webview started loading");
}

// This function allows me to intercept links clicked in a webview and open in
// a navigation window with a back button.
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    NSString *urlString = url.absoluteString;

    NSLog(@"urlstring is %@", urlString);

    // Only catching links without "mobile" in the url (i.e. stories)
    if ([urlString rangeOfString:@"/mobile"].location == NSNotFound && [urlString rangeOfString:@"facebook"].location == NSNotFound && [urlString rangeOfString:@"facebook"].location == NSNotFound &&[urlString rangeOfString:@"twitter"].location == NSNotFound && [urlString rangeOfString:@"fb://"].location == NSNotFound && [urlString rangeOfString:@"liverail"].location == NSNotFound && [urlString rangeOfString:@"about:blank"].location == NSNotFound) {
        //DetailViewController *detailView = [[DetailViewController alloc] init];
        //[self.navigationController pushViewController:detailView animated:YES];

        return NO;
    } else {
        return YES;
    }
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"error is %@", [error localizedDescription]);
}
[self.webViewForStories setDelegate:self] 
// This function allows me to intercept links clicked in a webview and open in
// a navigation window with a back button.
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    NSString *urlString = url.absoluteString;

    NSLog(@"urlstring is %@", urlString);

    // Only catching links without "mobile" in the url (i.e. stories)
    if ([urlString rangeOfString:@"/mobile"].location == NSNotFound && [urlString     rangeOfString:@"facebook"].location == NSNotFound && [urlString rangeOfString:@"facebook"].location == NSNotFound &&[urlString rangeOfString:@"twitter"].location == NSNotFound && [urlString rangeOfString:@"fb://"].location == NSNotFound && [urlString rangeOfString:@"liverail"].location == NSNotFound && [urlString rangeOfString:@"about:blank"].location == NSNotFound) {
        //DetailViewController *detailView = [[DetailViewController alloc] init];
        //[self.navigationController pushViewController:detailView animated:YES];

        return NO;
    } else {
        return YES;
    }
}