Undeclared delegate and shouldStartLoadWithRequest

限于喜欢 提交于 2019-12-11 23:23:07

问题


i am newer to coding in general! I am trying to create a webview that doesnt allow navigation to viewers. I have most of the coding typed up, but i have two undeclared errors and i am not sure how to solve this issue.

What i am trying to do is create a webView, but i would like to make it where the viewer of the webView cant navigate to other pages. If he/she does attempt too it does not fulfill the request.So basically it stays specifically on one page.

If i just need declare them in a really simple way then please show me and help. Thank you.

The Errors are shown below:

#import "ViewController.h"

@interface ViewController()
<UIWebViewDelegate>

@end

@implementation ViewController
@synthesize webView;

- (void)viewDidLoad
{
[super viewDidLoad];
webview:delegate = nil;
NSURL *url = [NSURL URLWithString:@"https://twitter.com/u_bett"];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlrequest];

}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request         navigationType:(UIWebViewNavigationType)navigationType
{
return NO;
}

回答1:


Your method contains lot of issues:

Change that like:

- (void)viewDidLoad
{
    [super viewDidLoad];
    webview.delegate = self;  
    NSURL *url = [NSURL URLWithString:@"https://twitter.com/u_bett"];    
    NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
    [webView loadRequest:urlrequest];

}

And implement shouldStartLoadWithRequest: like:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if(navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        return NO;
    }
    return YES;
}

Check this tutorial for UIWebView implementation. I would like to suggest you to learn Objective C thoroughly before starting the development. (Some investment at this point will help you to save a lot of time in future)



来源:https://stackoverflow.com/questions/20380565/undeclared-delegate-and-shouldstartloadwithrequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!