【问题标题】:I have two error : No visible @interface for 'UIWebview'我有两个错误:“UIWebview”没有可见的@interface
【发布时间】:2012-11-19 13:39:01
【问题描述】:

我有两个错误:“UIWebView”没有可见的@interface 声明选择器“highlightAllOccurencesOfString:”

另一个:“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

【问题讨论】:

    标签: objective-c ios uiwebview


    【解决方案1】:

    U 继承了 uiwebview 并将其命名为 SearchWebView,但是当您在 wbsecondviewcontroller 中创建 Web 视图的实例时,您使用常规 Web 视图而不是您创建的子类,并且常规 Web 视图没有两个额外的方法您为该自定义定义的。在 wbsecondviewcontroller.h 中的 @interface 上方执行 @class SearchWebView。然后在声明属性 UiWebView 的地方,将其声明为 SearchWebView。在 wbsecondviewcontroller 的 .m 文件中执行 #import "SearchWebView.h"

    【讨论】:

    • 另外:在SearchWebView.h 中将#import &lt;Foundation/Foundation&gt; 替换为#import &lt;UIKit/UIKit&gt;
    • 感谢 anser this.我尝试添加 @class SearchWebView 等等。然后我的程序错误消失了。但是现在,它有新的错误。我做这个程序。然后从 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:]: unrecognized selector sent to instance 0x7167520'
    • @user,如果您仍然得到相同的结果,您似乎完全忽略了这个答案建议。
    • 我想我没有忽略答案建议。我没有得到相同的结果。我只是有新的错误。我该怎么办?
    • 您必须阅读子类化的工作原理以及如何正确使用它,否则您将不断收到此类错误。查看调用 highlightAllOccurancesOfString 的每个地方,并确保该对象的类型为 SearchWebView 而不是 Uiwebview。如果在 .h 或 .m 文件中有类似 uiwebview *someView 的内容,则不能将其发送 highlightAllOccurancesOfString。它必须更改为 SearchWebView *someview。如果它解决了您正在寻找的原始问题,请不要忘记接受我的回答,以便其他有相同问题的人知道它有效。
    猜你喜欢
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多