2012-12-02 47 views
1

可能重複:
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 
+0

請不要只因爲沒有得到答案而再次提出相同的問題。 – borrrden

回答

1

這兩條線都是錯誤的,

[_webView highlightAllOccurencesOfString:@"不明"]; 
[_webView removeAllHighlights]; 

它應該是,

[self highlightAllOccurencesOfString:@"不明"]; 
[self removeAllHighlights]; 

您正在試圖調用highlightAllOccurencesOfString並在WBSecondViewController@interfaceUIWebview對象定義removeAllHighlights。編譯器無法在UIWebView@interface中找到它,因此錯誤消息爲No visible @interface for 'UIWebView' declares the selector ...

+1

謝謝你的回答。我明白了。 – hekiru

1

highlightAllOccurencesOfStringremoveAllHighlights在你WBSecondViewController定義的方法,而你正試圖打電話給他們一個UIWebView對象。試試這個:

-(IBAction)searchButtonPressed:(id)sender{ 
    NSLog(@"highlighttes"); 
    [self highlightAllOccurencesOfString:@"不明"]; 
} 

-(IBAction)clearHighlights:(id)sender{ 
    [self removeAllHighlights]; 
} 

這至少會編譯。

+0

謝謝你的回答。我明白了。 – hekiru