unrecognized selector while calling using addTarget - iphone

I am using addTarget on custom cell button like:
[cell.btnGet addTarget:self action:#selector(getLocal:cell:) forControlEvents:UIControlEventTouchUpInside];
It should be call this method:
-(void)getLocal:(id)sender withcell:(GroupListCell *)cell
{
// code for implement
}
but when I am click the button it is throwing error like:
2013-02-27 14:28:56.533 iOSPlayer[704:11303] -[GroupView getLocal:cell:]: unrecognized selector sent to instance 0x72e1290
2013-02-27 14:28:56.534 iOSPlayer[704:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GroupView getLocal:cell:]: unrecognized selector sent to instance 0x72e1290'
What is the issue here?

try this:
[cell.btnGet addTarget:self action:#selector(getLocal:withcell:) forControlEvents:UIControlEventTouchUpInside];

That action method is called:
getLocal:withcell:
and not:
getLocal:cell:
It also doesn't match any of the acceptable action method signatures, which are:
- (IBAction)doSomething;
- (IBAction)doSomething:(id)sender;
- (IBAction)action:(id)sender forEvent:(UIEvent *)event;
(see this Apple guide)

Related

Application terminated when tapping custom button on navigation bar

I made an custom button for a navigation bar, but when I tap it, it terminates
-(void)viewDidLoad
{
UIImage *backButtonImage = [UIImage imageNamed:#"button.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
[backButton addTarget:self action:#selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBackBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = customBackBarItem;
}
-(void)goBackOne
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
the output is
2013-07-28 15:00:37.932 Habit Pal[1562:c07] -[SleepModeViewController back]: unrecognized selector sent to instance 0x9167300
2013-07-28 15:00:37.932 Habit Pal[1562:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SleepModeViewController back]: unrecognized selector sent to instance 0x9167300'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0x10e4705 0x182c0 0x18258 0xd9021 0xd957f 0xd86e8 0x47cef 0x47f02 0x25d4a 0x17698 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x213d 0x2065)
libc++abi.dylib: terminate called throwing an exception
(lldb)
You button is trying use the selector back on your SleepModeViewController, but you've actually named the method -goBackOne. You fix it, either rename the -goBackOne method to -back, or change the name of the selector to goBackOne. For example:
// The selector must actually match a method name on the target
[backButton addTarget:self action:#selector(goBackOne) forControlEvents:UIControlEventTouchUpInside];
It's important that the selector name and method names match. The error shows that your problem is that the selector named -back doesn't exist. When your app terminates with these errors, you should check that all your #selector() statements match actual method names.

UIImageview set image crash

I'm setting image to a UIImageView using in the below code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for(int i=0;i<[radioButtons count];i++){
[[radioButtons objectAtIndex:i] setImage:[UIImage imageNamed:#"checkbox_unchecked.png"]];
}
UIImageView *imageViews=(UIImageView *)[self.view viewWithTag:indexPath.row];
[imageViews setImage:[UIImage imageNamed:#"checkbox_checked.png"]];
}
So on clicking any tableview cell the images gets sets. But once if I click on objectatindex:0
then the app crashes. I'm unable to fix this.
Below is the crash log:
2012-08-20 16:25:36.321 EventApp[2422:12503] -[UIView setImage:]: unrecognized selector sent to instance 0x79642b0
2012-08-20 16:25:36.321 EventApp[2422:12503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x79642b0'
*** First throw call stack:
(0x1de3022 0x1c03cd6 0x1de4cbd 0x1d49ed0 0x1d49cb2 0x7a98c 0xc615c5 0xc617fa 0x14f685d 0x1db7936 0x1db73d7 0x1d1a790 0x1d19d84 0x1d19c9b 0x1be57d8 0x1be588a 0xbd0626 0x380a2 0x23b5)
terminate called throwing an exception(lldb)
I think you are not getting UIImageView Object,you are getting uiview types object that's why it crashes. you should try to Define another tag property like 999+indexPath.row. Got it somewhere you define the tag=0 or IB automatically takes tag=0 to all object so it taking uiview with tag 0 not uiimageView
this means that you are sending message -(void)setImage to UIView, not to UIImageView. Make sure that view with tag indexPath.row and all radioButtons in array are actually UIImageView

Unrecognized Selector Sent To Instance, iPhone Error

I get the error
"012-02-10 13:54:52.570 HelloWorld[14275:10103]
-[HelloWorldViewController buttonPressed]: unrecognized selector sent to instance 0x6cc0c50 2012-02-10 13:54:52.572 HelloWorld[14275:10103]
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HelloWorldViewController
buttonPressed]: unrecognized selector sent to instance 0x6cc0c50'".
This is the offending text:
-(void)buttonPressed:(id)sender {
UIButton *button = (UIButton*)sender;
NSString *text = [button titleForState:UIControlStateNormal];
NSLog(#"%#",text);
}
I know this because if I change the code to this:
-(void)buttonPressed {
NSLog(#"Button Pressed");
}
It then works correctly.
However I need the text from the component that sent the message. The components are not drag and dropped with IB. They are allocated, initialized and placed in the loadView method. To each of my buttons I have added buttonPressed as the action listener.
The error unrecognized-selector could be due to a missing :.
[yourbutton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
instead of
[yourbutton addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
In the first case you call -(void)buttonPressed:(id)sender. In the second instead you call -(void)buttonPressed.
But if you provide more code for your UIButton, it could be simpler to understand what is going on.
In the first (not working) case you have -(void)buttonPressed:(id)sender and in the second (working) you have -(void)buttonPressed. Obviously your button calls the function without argument.
that could be the case when you have added the #selector(buttonPressed:) for button touch event, you have forgotten to put the : with method name.
you can check for the same.

Why it doesn't recognise my selector?

I want to change the action of an UIButton and it gives me an exception when touching the button.
[grabRedeem removeTarget:self action:#selector(grabbOffer:) forControlEvents:UIControlEventTouchUpInside];
[grabRedeem addTarget:self action:#selector(redeemOffer:) forControlEvents:UIControlEventTouchUpInside];
grabbOffer and redeemOffer are IBActions that are implemented with no parameters.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController grabbOffer:]: unrecognized selector sent to instance 0x1e8bf0'
What could be the reason?
Have you tried to remove the colon:
[grabRedeem removeTarget:self action:#selector(grabbOffer) forControlEvents:UIControlEventTouchUpInside];
[grabRedeem addTarget:self action:#selector(redeemOffer) forControlEvents:UIControlEventTouchUpInside];
you use the semicolon when you want to use a parameter:
-(void)grabbOffer:(id)sender;
If you function implemented with no parameters use: #selector(grabbOffer) instead #selector(grabbOffer:)

dismissModalViewControllerAnimated makes my app crash :(

I'm creating an iPad app, and I have two classes: NWRootViewController : UITableViewController and UINewFeedViewController : UIViewController. In NWRootViewController I have an UIBarButtonItem, which, when tapped, pops up a modal view controller called NWNewFeedViewController:
// THIS CODE IS IN NWROOTVIEWCONTROLLER.M
// New Feed
-(IBAction)showNewFeedViewAction:(id)sender {
[newFeedViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentModalViewController:newFeedViewController animated:YES];
}
This works fine. However, in the NWNewFeedViewController's view, I have another UIBarButtonItem which does this when tapped:
// THIS CODE IS IN NWNEWFEEDCONTROLLER.M
// Buttons
-(IBAction)cancelAction:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
When I tap this button, the app crashes with:
2010-04-10 12:39:46.703 News[580:207] *** -[NWDetailViewController cancelAction:]: unrecognized selector sent to instance 0x4741110
2010-04-10 12:39:46.705 News[580:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NWDetailViewController cancelAction:]: unrecognized selector sent to instance 0x4741110'
2010-04-10 12:39:46.705 News[580:207] Stack: (
40878667,
2458187017,
41150267,
40613142,
40609810,
2776006,
4876265,
2776006,
3246293,
3255055,
3250242,
2899304,
2793965,
2825287,
49238396,
40419388,
40415304,
49232029,
49232226,
2817505
)
Can anyone help me? Thanks
Your cancel button has a target of your detail controller; you meant to target your new feed controller. So check how you configured the cancel button.
Your app is trying to call an object that has already been released. Enable zombie objects as explained here to find out what object is trying to be accessed.