为什么我会收到此错误?在Xcode

时间:2012-12-02 10:39:08

标签: objective-c ios xcode uiwebview

  

可能重复:
  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

2 个答案:

答案 0 :(得分:1)

highlightAllOccurencesOfStringremoveAllHighlightsWBSecondViewController中定义的方法,当您尝试在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个对象中定义的UIWebviewUIWebView。编译器无法在@interfaceNo visible @interface for 'UIWebView' declares the selector ...中找到它,因此错误消息为{{1}}