objective-c - 我有两个错误 : No visible @interface for 'UIWebview'

标签 objective-c ios uiwebview

我有两个错误:“UIWebView”没有可见的@interface声明选择器“highlightAllOccurencesOfString:”

另一个:'UIWebView'没有可见的@interface声明选择器'removeAllHighlights' 请有人帮助我。

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

#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

#import <Foundation/Foundation.h>

@interface SearchWebView : UIWebView

- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
- (void)removeAllHighlights;

@end

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

最佳答案

您对 uiwebview 进行了子类化并将其称为 SearchWebView,但是当您在 wbsecondviewcontroller 中创建 Web View 的实例时,您使用常规 Web View 而不是您创建的子类,并且常规 Web View 没有这两个额外的方法您为该自定义定义的。在 wbsecondviewcontroller.h 中的 @interface 上方执行 @class SearchWebView。然后,在声明 UiWebView 属性的地方,将其声明为 SearchWebView。在 wbsecondviewcontroller 的 .m 文件中执行 #import "SearchWebView.h"

关于objective-c - 我有两个错误 : No visible @interface for 'UIWebview' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13660379/

相关文章:

ios - 仅在通过解析保存数据后执行/触发 segue

ios - 在 iOS 上打开与 Icecast 服务器的套接字连接

ios - #define 指令上的这个错误是什么?

ios - 如何在 iOS 中使用预设的 cookie 或 header 在 Safari 中打开 URL?

ios - UITableViewCell 仅在滚动时正确布局

ios - 检测是否在 UITextField 中输入了 "space",并移动到下一个 UITextField

iphone - 从 UIWebView 中的电影播放器​​获取通知

iphone - 如何禁用UIWebview中的放大镜?

iphone - UIWebView完成加载事件

objective-c - 在 Objective-C 中前向声明 ns_options