我有一個視圖控制的應用程序。在我的xib上,我沒有網頁瀏覽,但是我有一些按鈕,可以顯示帶有網頁瀏覽的類。所以點擊按鈕一個和一個uiwebview彈出如此等等。shouldStartLoadwithRequest未在子類中調用
現在在我的一個課上,我拉起了一個遠程網頁,其上有一個鏈接。我想用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;
}}
但我什麼也沒有(沒有我的NSLogs的)。我曾嘗試將此放入我的Tenth.m班,但仍然沒有任何結果。我看過其他例子,甚至下載了一個,但它只使用viewcontroller和委託類。沒有第三堂課。
我失去了爲什麼它沒有被調用。
這是我的第三類
#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
遠程頁面代碼
<a href="didTap://button1">hello</a>
Tenth.h文件
#import <UIKit/UIKit.h>
@interface Tenth : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *category10;
}
-(IBAction)back;
@end
1.您設定的WebView委託'self'? 2.不應該'[@「didTap」isEqual:scheme]''[@「didTap」isEqualToString:scheme]'? –