未授权的委托和shouldStartLoadWithRequest [英] Undeclared delegate and shouldStartLoadWithRequest
问题描述
我想要做的是创建一个webView,但我想让它在webView的浏览器不能导航到其他页面。如果他/她也试图尝试,它不能满足请求。因此,它基本上保留在一个页面上。
如果我只需要以一种非常简单的方式声明它们,请告诉我和帮助。谢谢。
错误如下所示:
#importViewController。 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 *)请求navigationType:(UIWebViewNavigationType)navigationType
{
return NO;
}
您的方法包含很多问题:
更改如下:
- (void)viewDidLoad
{
[super viewDidLoad];
webview.delegate = self;
NSURL * url = [NSURL URLWithString:@https://twitter.com/u_bett];
NSURLRequest * urlrequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlrequest];
}
并实现 shouldStartLoadWithRequest: code> like:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest :( NSURLRequest *)请求navigationType :(UIWebViewNavigationType)navigationType
{
if(navigationType == UIWebViewNavigationTypeLinkClicked)
{
return NO;
}
return YES;
}
查看本教程 UIWebView实现 / / build-building-a-web-browser-with / uiwebview-part-1 /
我想建议你学习 Objective C 。 (在这一点上的一些投资将有助于您节省未来的大量时间)
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;
}
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)
这篇关于未授权的委托和shouldStartLoadWithRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!