可能重複:
I have two error : No visible @interface for ‘UIWebview’爲什麼我得到這個錯誤?在Xcode中
爲什麼我在Xcode中得到這個錯誤。錯誤在於:'UIWebView'聲明選擇器'highlightAllOccurencesOfString:'沒有可見的@interface,'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
請不要只因爲沒有得到答案而再次提出相同的問題。 – borrrden