可能重复:
I have two error : No visible @interface for ‘UIWebview’
为什么我在Xcode上遇到此错误。错误是:'UIWebView'没有可见的@interface声明选择器'highlightAllOccurencesOfString:'并且'UIWebView'没有可见的@interface声明了选择器'removeAllHighlights'。哪里错了?
WBSecondViewController.h
#import <UIKit/UIKit.h>
@interface WBSecondViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>{}
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIToolbar *webToolBar;
- (IBAction)searchButtonPressed:(id)sender;
- (IBAction)clearHighlights:(id)sender;
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
- (void)removeAllHighlights;
@end
WBSecondViewController.m
#import "WBSecondViewController.h"
@interface WBSecondViewController ()
@end
@implementation WBSecondViewController
-(IBAction)searchButtonPressed:(id)sender{
NSLog(@"highlighttes");
[_webView highlightAllOccurencesOfString:@"不明"];
}
-(IBAction)clearHighlights:(id)sender{
[_webView removeAllHighlights];
}
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"UIWebViewSearch" ofType:@"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[_webView stringByEvaluatingJavaScriptFromString:jsCode];
NSString *startSearch = [NSString stringWithFormat:@"uiWebview_HighlightAllOccurencesOfString('%@')",str];
[_webView stringByEvaluatingJavaScriptFromString:startSearch];
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:@"uiWebview_SearchResultCount"];
return [result integerValue];
}
- (void)removeAllHighlights
{
[_webView stringByEvaluatingJavaScriptFromString:@"uiWebview_RemoveAllHighlights()"];
}
@end
答案 0 :(得分:1)
highlightAllOccurencesOfString
和removeAllHighlights
是WBSecondViewController
中定义的方法,当您尝试在UIWebView
对象上调用它们时。试试这个:
-(IBAction)searchButtonPressed:(id)sender{
NSLog(@"highlighttes");
[self highlightAllOccurencesOfString:@"不明"];
}
-(IBAction)clearHighlights:(id)sender{
[self removeAllHighlights];
}
这至少会编译。
答案 1 :(得分:1)
这两行是错的,
[_webView highlightAllOccurencesOfString:@"不明"];
[_webView removeAllHighlights];
应该是,
[self highlightAllOccurencesOfString:@"不明"];
[self removeAllHighlights];
您正在尝试拨打highlightAllOccurencesOfString
removeAllHighlights
WBSecondViewController
但@interface
个对象中定义的UIWebview
和UIWebView
。编译器无法在@interface
类No visible @interface for 'UIWebView' declares the selector ...
中找到它,因此错误消息为{{1}}