我有兩個錯誤:「UIWebView的」不可見@interface聲明選擇「highlightAllOccurencesOfString:」我有兩個錯誤:不可見@interface「UIWebView的」
另一個問題:對「的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
另外:在'SearchWebView.h'中用'#import'替換'#import ' –
JustSid
謝謝anser this.I嘗試了add @class SearchWebView等等on.Then我的程序的錯誤消失。但現在,它有新的錯誤。我做這個程序。然後從Xcode.2012-12-02 00:14:24.678 WordBook [6721:c07] - [UIWebView highlightAllOccurencesOfString: ]:無法識別的選擇器發送到實例0x7167520 2012-12-02 00:14:24.678 WordBook [6721:c07] ***終止應用程序由於未捕獲異常'NSInvalidArgumentException',原因:' - [UIWebView highlightAllOccurencesOfString:]:無法識別的選擇器發送到實例0x7167520' – hekiru
@user,你似乎完全忽略了這個答案的建議,如果你仍然是g取得相同的結果。 – CodaFi