UIBarButtonItems 的操作处理程序出现问题
我的工具栏按钮代码面临一个非常愚蠢的问题。我正在使用以下代码,并且代码中已经有了操作处理函数,但是每当我单击按钮时,我都会收到错误:“ - [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是因为这一行,
您已将
self.webViews
设为目标,但我认为您的意思是self
。It's probably because of this line,
You have made
self.webViews
the target but I think you meantself
.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.