shouldStartLoadwithRequest未在子类中调用

Ric*_*ick 2 iphone ipad ios

我有一个视图控制的应用程序.在我的xib上我没有webview,但我确实有按钮可以调出带有webview的类.所以按下按钮一,然后弹出一个uiwebview,等等.

现在在我的一个课程中,我拉出一个有链接的远程网页.我想用shouldStartLoadwithrequest覆盖那个按钮链接.从来没有像现在这样被称呼.

现在我的班叫做Tenth.m,我的视图控制器中有这个代码

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

NSLog(@" Test spot 1");
NSString* scheme = [[request URL] scheme];
if ([@"didTap" isEqual:scheme]) {
    // Call your method
     NSLog(@" Test spot 2");
    [self didTapButton1];
    return NO;
} else {
     NSLog(@" Test spot 3");
    return YES;
}}
Run Code Online (Sandbox Code Playgroud)

但我什么都没得到(我的NSLog都没有).我已经尝试将它放入我的Tenth.m课程中,但仍然没有.我查看了其他示例,甚至下载了一个但它只使用了viewcontroller和delegates类.没有第三类.

我迷失了为什么它没有被召唤.

这是我的第三堂课

#import "Tenth.h"


@implementation Tenth

- (void)awakeFromNib
{
[category10 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mywebsite.com/api/didtap.php"]]];

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)dealloc
{
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{

 [super viewDidLoad];
}


- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}

@end
Run Code Online (Sandbox Code Playgroud)

远程页面代码

    <a href="didTap://button1">hello</a>
Run Code Online (Sandbox Code Playgroud)

Tenth.h文件

#import <UIKit/UIKit.h>


@interface Tenth : UIViewController <UIWebViewDelegate> {

IBOutlet UIWebView *category10;

}

-(IBAction)back;
@end
Run Code Online (Sandbox Code Playgroud)

Mat*_*ham 5

我的第一个猜测是Web视图没有设置其委托.为了打电话

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
Run Code Online (Sandbox Code Playgroud)

包含此方法的类需要设置为webview的委托.所以在代码中的某处应该有一个类似的行webView.delegate = <variable>,其中变量是实现该shouldStartLoadWithRequest:方法的类的实例.

当webView是viewController视图的子视图时,这通常是"自我".但是你描述你的应用程序的方式,我不确定它是否是自我,但听起来它不是自我,而是一个不同类的实例的名称.