UIBarButtonItems 的操作处理程序出现问题

发布于 2024-11-16 17:07:18 字数 1545 浏览 12 评论 0原文

我的工具栏按钮代码面临一个非常愚蠢的问题。我正在使用以下代码,并且代码中已经有了操作处理函数,但是每当我单击按钮时,我都会收到错误:“ - [UIWebView function_name]:无法识别的选择器发送到实例 0x.... ”任何人都可以帮忙吗?谢谢。

.h 文件内:

- (void) goBackHandler;
- (void) goForwardHandler;
- (void) goSafari;

.m 文件内:

UIBarButtonItem *backButton=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackHandler)]autorelease];

UIBarButtonItem *forwardButton=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward.png"] style:UIBarButtonItemStylePlain target:self.webViews action:@selector(goForwardHandler) ] autorelease];    

UIBarButtonItem *safariButton=[[[UIBarButtonItem alloc] initWithTitle:@"Safari" style:UIBarButtonItemStyleBordered target:self action:@selector(goSafari)]autorelease];

UIBarButtonItem *flex=[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]autorelease];

NSArray *arrayOfButtons=[[[NSArray alloc] initWithObjects:backButton,flex,safariButton,flex,forwardButton, nil]autorelease];

[self setToolbarItems:arrayOfButtons];





- (void) goBackHandler
{

if ([self.webViews canGoBack])
{
    [self.webViews goBack];
}

}

- (void) goForwardHandler
{
if ([self.webViews canGoForward])
{
    [self.webViews goForward];
}
}

- (void) goSafari
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self.webViews stringByEvaluatingJavaScriptFromString:@"window.location"]]];
}

I am facing a very silly problem with my code for buttons in the toolbar. I am using the following code and I already have the action handler functions in the code, but whenever I am clicking on the buttons, I am getting the error: " - [UIWebView function_name]: unrecognized selector sent to instance 0x....." Can anyone kindly help ? Thanks.

inside the .h file:

- (void) goBackHandler;
- (void) goForwardHandler;
- (void) goSafari;

inside the .m file :

UIBarButtonItem *backButton=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackHandler)]autorelease];

UIBarButtonItem *forwardButton=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward.png"] style:UIBarButtonItemStylePlain target:self.webViews action:@selector(goForwardHandler) ] autorelease];    

UIBarButtonItem *safariButton=[[[UIBarButtonItem alloc] initWithTitle:@"Safari" style:UIBarButtonItemStyleBordered target:self action:@selector(goSafari)]autorelease];

UIBarButtonItem *flex=[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]autorelease];

NSArray *arrayOfButtons=[[[NSArray alloc] initWithObjects:backButton,flex,safariButton,flex,forwardButton, nil]autorelease];

[self setToolbarItems:arrayOfButtons];





- (void) goBackHandler
{

if ([self.webViews canGoBack])
{
    [self.webViews goBack];
}

}

- (void) goForwardHandler
{
if ([self.webViews canGoForward])
{
    [self.webViews goForward];
}
}

- (void) goSafari
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self.webViews stringByEvaluatingJavaScriptFromString:@"window.location"]]];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的心爱 2024-11-23 17:07:18

可能是因为这一行,

UIBarButtonItem *forwardButton=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward.png"] style:UIBarButtonItemStylePlain target:self.webViews action:@selector(goForwardHandler) ] autorelease]; 

您已将 self.webViews 设为目标,但我认为您的意思是 self

It's probably because of this line,

UIBarButtonItem *forwardButton=[[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward.png"] style:UIBarButtonItemStylePlain target:self.webViews action:@selector(goForwardHandler) ] autorelease]; 

You have made self.webViews the target but I think you meant self.

默嘫て 2024-11-23 17:07:18

target:action: 对的 Target 是实现 action: 参数中指定的方法的对象。因此,在这种情况下,您的目标将是每个按钮的 self。

The Target of a target:action: pair is the object which implements the method specified in the action: parameter. So in this case, your target will be self for each of those buttons.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文