Perform segue from unbutton results in "unrecognized selector" error - objective-c

I have implemented a simple segue from a button click. Here is the view controller code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
{
if (self.categoryInt == 1)
[segue.destinationViewController setCategoryKey:SD_ADDITION];
else if (self.categoryInt == 2)
[segue.destinationViewController setCategoryKey:SD_SUBTRACTION];
}}
- (IBAction)category1Selected:(id)sender {
self.categoryInt = 1;
[self performSegueWithIdentifier:#"ShowWorksheet" sender:self];}
From the log messages, I can see that it ran through the ViewDidLoad on the destinationviewcontroller completely but then it errors out
with: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainMenuViewController categorySelected:]: unrecognized selector sent to instance 0x75360e0'
I have not implemented any specific selectors on these buttons. Also there is no "categorySelected" method in my MainMenuViewController. The method being invoked is "category1Selected". What is causing this error?

I think you answered the question yourself. You are somehow sending "categorySelected" when you SHOULD be sending category1Selected.
Check to see if you previously wired a button to categorySelected in interface builder. If you had previously done this, but then changed the name of categorySelected to category1Selected in your code, interface builder would probably not update.

This is usually a connection error, go to your connections inspector and make sure all is correct there.
If your not sure disconnect all the connections and re make the connections double checking everything.
Also Make sure you haven't connected the action button as an outlet in addition to its action command.

Related

When segue is performing throws unrecognized selector sent to instance error message showed?

I've been looking for a solution since yesterday, and i still can't figure out actual problem.
My app has been worked for 2 months on ios8 devices. I also set it up for ios7 devices, but I didn't know it was crashing on ios7 devices because of segue.
This is prepareSegue function:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if (segue.identifier == "navigateToSettingsView") {
if let settingsView = segue.destinationViewController as? SettingControllerView
{
settingsView.isSetup = self.isSetup
}
}
}
My segue style is present modally and current context.
I have navigate function to perform segue like this:
func navigateToSettings() {
// call setting view for adjusting settings
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("navigateToSettingsView", sender: self)
})
}
I'm still tracing debug now, it's getting me annoyed so much. And in the debugger log area. The only prompt is 'containsString:' and unrecognized selector sent to instance. I know unrecognized selector issue, sorry for that. But my problem has no reason on debug log.Also, i can't use allocations instruments because of ios7.Eventhough, I'm not using any String contains function. I know the issue rangeOfString :S
[__NSCFString containsString:]: unrecognized selector sent to instance
I just ran into this issue as well, however my problem is in iOS 6.1 so it may be different. I didn't try to re-produce the issue in iOS 7 yet.
What I discovered was a newly added UITextField on my storyboard caused the crash. Removing the UITextField fixed the problem.
You may want to remove some recent UI elements from your storyboard and see if that helps. I found copying an existing UITextField and pasting it where I wanted the new one still allowed my app to run on iOS 6.1.

Reload Data throwing unrecognized selector sent to instance

I seem to be experiencing a small error when dismissing a view and navigating back to a ViewController (with a UITableView)
This is the code that loads the data into the tableView
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[getData getSavedTanks:^(NSArray *results) {
self.array = results;
[self.tankList reloadData];
NSLog(#"%#", results);
}];
}
The followup view in the stack is properly called, but when the view is dismissed, it seems as though the tableView has trouble reloading the data, and is throwing this error:
2014-04-28 21:15:57.698 ReefTrack[10205:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFObject reloadData]: unrecognized selector sent to instance 0x10be93210'
Not really sure how to handle this. I'm having trouble understanding why reloadData is throwing an error. I checked to see if there are any errant Segues pointing towards reload data but there doesn't appear to be. Anyone have any thoughts on this?
UPDATE:
This was solved by placing the entire function in viewDidLoad.

Button in a popover will display text in the main view controller

My popover has a button which when clicked, will display a text in the main view controller.
Here's my code for the button:
- (IBAction)print:(UIButton *)sender {
self.displayText.text= #"Hello World";
}
By the way, I followed the tutorial here.
I tried to run the program and I'm getting this error when I click the "print hello world" button:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PopoverViewController
print:]: unrecognized selector sent to instance 0xe379240'
I thought that when it's a button in popover, it's a different case. And i've followed few solutions to this problem (posted also by people who encountered the same problem) already but i can't seem to solve it. Still having errors. Hope you could help me.
Thank you.
When you set the action for the message, you need to send the message to your View Controller instead of to your Popover.
Which you can't really do when you have them in separate xib's.
There are a few different ways of approaching this, one of which would be to implement a delegate in your popover class, and when you create the popover set the delegate to self (the view controller which created it) and implement the delegate method. Then, when you press the button, it calls a function in your popover class which then calls your delegate's method.

Can I have a block of code run only if user is on iPhone vs iPad?

I have a master-detail app that is working great for the iPad. However, the iPhone version doesn't work because a variable that is being sent to the DetailViewController in the iPad version doesn't send to the iPhone DetailViewController. I can fix this with a single line of code in MasterViewController implementation:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
self.detailViewController=segue.destinationViewController;
}
Unfortunately, when I implement that code, the iPad version stops working. I get an exception when I go from another view controller (HomeViewController) back to DetailViewController. That error log is:
2012-07-14 14:29:12.924 46 Tracker[2772:11603] -[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0
2012-07-14 14:29:12.925 46 Tracker[2772:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0'
*** First throw call stack:
(0x148a022 0x201acd6 0x148bcbd 0x13f0ed0 0x13f0cb2 0x2cb0 0x2d75c5 0x2d77fa 0xb6c85d 0x145e936 0x145e3d7 0x13c1790 0x13c0d84 0x13c0c9b 0x16a07d8 0x16a088a 0x246626 0x1fdd 0x1f45)
terminate called throwing an exception(lldb)
So, is there any way I can run that first block of code only when the user is on the iPhone? Or, can I fix the code to make it work properly on both devices?
Here is a link to my iPad storyboard to (hopefully) make it more clear. I have a problem when I click on a table cell AFTER going from HomeViewController back to DetailViewController: http://www.grapekeeper.com/storyboards.png
Perhaps the following?
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// perform iPad logic
} else {
// perform iPhone logic
}

Button Click Gives Different Errors On Subsequent Launches

I've never seen this response before, where the same action, on different runs of the same app throws different errors.
I have an IBAction for a button (that just logs sender) in an NSViewController subclass that throws the errors upon clicking the button (this is an OSX app). I'm getting these (so far):
-[NSArrayM buttonClick:]: unrecognized selector sent to instance
-[__NSCFDictionary buttonClick:]: unrecognized selector sent to instance
-[__NSCFSet buttonClick:]: unrecognized selector sent to instance
-[NSRunLoop buttonClick:]: unrecognized selector sent to instance
And, the dreaded EXC_BAD_ACCESS.
The only code in this test app is this in the app delegate to instantiate the view controller:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
TestController *controller = [[TestController alloc] initWithNibName:#"TestController" bundle:nil];
[self.window.contentView addSubview:controller.view];
}
And this IBAction in the view controller subclass:
-(IBAction)buttonClick:(id)sender {
NSLog(#"%#",sender);
}
The IBAction which is implemented in the view controller is connected in IB (through File's Owner) to the button which is in its view.
I can't understand how I can get so many different error messages in such a simple program. Could this be a problem with the view controller not being in the responder chain? If so, why should it throw errors, shouldn't the message just get sent up the chain and then be discarded?
I've tried having the controller's view set the controller as the next responder (with [controller.view setNextResponder:controller];), but that just gives me the EXC_BAD_ACCESS error upon launch.
Ok, I fixed this with a pointer from Shane Stanley over at MacScripter (I had made another version in ApplescriptObjC to ask the question over there, but that version worked). It's a matter of memory management -- too easy to forget about that when using ARC. The TestController instance was being deallocated before I was sending the IBAction to it. This explains the variable error messages, because sending a message to a deallocated object can point to anything. The problem was fixed by declaring a property (as retain) for the TestController instance, controller.