我有两个错误:"UIWebview"没有可见的@interface [英] I have two error : No visible @interface for 'UIWebview'
问题描述
我有两个错误:'UIWebView'的不可见@interface声明选择器'highlightAllOccurencesOfString:'
I have two error :No visible @interface for 'UIWebView' declares the selector 'highlightAllOccurencesOfString:'
另一种:'UIWebView'的不可见@interface声明选择器'removeAllHighlights' 请有人帮我.
another one:No visible @interface for 'UIWebView' declares the selector 'removeAllHighlights' Please someone help me.
WBSecondViewController.h
WBSecondViewController.h
#import <UIKit/UIKit.h>
@interface WBSecondViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>{
}
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property(copy) NSArray *menuItems;
@property (weak, nonatomic) IBOutlet UIToolbar *webToolBar;
- (IBAction)back:(id)sender;
- (IBAction)foward:(id)sender;
-(IBAction)searchButtonPressed:(id)sender;
-(IBAction)clearHighlights:(id)sender;
@end
WBSecondViewController.m
WBSecondViewController.m
#import "WBSecondViewController.h"
#import "Word.h"
#import "WordController.h"
#import "AddWordController.h"
#import "WBAppDelegate.h"
#import "WBFirstViewController.h"
#import "SearchWebView.h"
@interface WBSecondViewController ()
@end
@implementation WBSecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Second", @"Second");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}
- (void)viewDidLoad
{
UIMenuController *menu = [UIMenuController sharedMenuController];
[super viewDidLoad];
NSURL *theURL = [NSURL URLWithString:@"http://www.google.co.jp"];
[_webView loadRequest:[NSURLRequest requestWithURL:theURL]];
}
-(IBAction)searchButtonPressed:(id)sender{
[_webView highlightAllOccurencesOfString:@"cat"];
}
-(IBAction)clearHighlights:(id)sender{
[_webView removeAllHighlights];
}
SearchWebView.h
SearchWebView.h
#import <Foundation/Foundation.h>
@interface SearchWebView : UIWebView
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
- (void)removeAllHighlights;
@end
SearchWebView.m
SearchWebView.m
#import "SearchWebView.h"
@implementation SearchWebView
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"UIWebViewSearch" ofType:@"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self stringByEvaluatingJavaScriptFromString:jsCode];
NSString *startSearch = [NSString stringWithFormat:@"uiWebview_HighlightAllOccurencesOfString('%@')",str];
[self stringByEvaluatingJavaScriptFromString:startSearch];
NSString *result = [self stringByEvaluatingJavaScriptFromString:@"uiWebview_SearchResultCount"];
return [result integerValue];
}
- (void)removeAllHighlights
{
[self stringByEvaluatingJavaScriptFromString:@"uiWebview_RemoveAllHighlights()"];
}
@end
推荐答案
U将uiwebview子类化,并将其命名为SearchWebView,但是当您在wbsecondviewcontroller中创建Web视图的实例时,您将使用常规Web视图而不是您创建的普通Web视图没有为该自定义方法定义的两种额外方法.在wbsecondviewcontroller.h中@interface上方,执行@class SearchWebView
.然后,在声明属性UiWebView的地方,将其声明为SearchWebView.在wbsecondviewcontroller的.m文件中,执行#import "SearchWebView.h"
U have subclassed uiwebview and called it SearchWebView but then when you create an instance of web view in your wbsecondviewcontroller, you use a regular web view instead of the subclass that you created and the regular web view does not have the two extra methods that you defined for that custom one. Above @interface in the wbsecondviewcontroller.h do @class SearchWebView
. Then where you declare the property UiWebView, declare it as a SearchWebView instead. In the .m file of the wbsecondviewcontroller do #import "SearchWebView.h"
这篇关于我有两个错误:"UIWebview"没有可见的@interface的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!