2016-05-30 8 views
0

ウェブビューがバウンスするのを止めようとしているときに、ユーザーがアプリ/スクリーンをドラッグしたときに上に空白が表示されます。Webビューのバウンスを停止するとエラーが表示されます

#import "Webview.h" 

@interface Webview() 

@end 

@implementation Webview 
@synthesize webView; 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    NSString *urlAddress= [[NSBundle mainBundle] pathForResource:@"demos/index" ofType:@"html"]; 
    NSURL *url = [NSURL fileURLWithPath: urlAddress]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

    [webView loadRequest:requestObj]; 

    webView.scrollView.delegate = self; 

    webView.scrollView.bounces = NO; 
    } 




- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 
    //The webview is is scrolling 
    int yPosition = [[webView stringByEvaluatingJavaScriptFromString: @"scrollY"] intValue]; 

    if([[webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue] - yPosition == webView.frame.size.height) 
    { 
     //The user scrolled to the bottom of the webview 
     webView.scrollView.bounces = YES; 
    }else if([[webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue] - yPosition > webView.frame.size.height + 100){ 
     webView.scrollView.bounces = NO; 
    } 

} 

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{ 
    NSLog(@"Finish"); 
} 



/* 
#pragma mark - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 
} 
*/ 

@end 

メッセージを持つ:これは動作しないコードであるomcompatibleタイプから 'ID _Nullable' に割り当て 'のWebView * constの__strong'

答えて

0

そのエラーがライン上にある場合:

_webView.scrollView.delegate = self; 

...あなたのwebViewインスタンスが正しいタイプではないというエラーです。あなたのwebViewインスタンスがUIWebViewのサブクラスである

  1. チェック。
  2. あなたは、インターフェイスのプロトコル宣言を含むことによって、UIScrollViewDelegateプロトコルを採用する必要がありますのUIViewController `の代わりに` @interfaceのWebViewの() `: @interface ViewController : UIViewController <UIScrollViewDelegate>
+0

私は' @interface ViewControllerを置くべきか? –

+0

'UIScrollViewDelegate'を採用している限り、上手くいくはずです。それでもエラーが発生した場合は、クラスにアクセスできるブレークポイントを設定し、 'po [var_name class]'を使用してクラス・クラスをコンソールに表示します。 – Sheamus

関連する問題