Reputation: 2982
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"]]];
}
Upvotes: 0
Views: 2457
Reputation: 7758
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.
Upvotes: 0
Reputation: 44633
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
.
Upvotes: 1