There are so many cases for "Unrecognized Selector Sent To Instance", I don't think I will find mine in so many threads. Or if I do it will take a month or so.
To be short. I receive this error, and my situation is:
I have a table view displaying recipes that are fetched from Core Data. When segue fires, it gets destination controller (which is UITabBarController), and provides a recipe for it.
The code for the segue method is:
if ([segue.identifier isEqualToString:#"RecipeTabBarController"]) {
RecipeTabBarController *VC = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Recipe *recipe = (Recipe*)[_controller objectAtIndexPath:indexPath];
VC.recipe = recipe;
}
TabBarController (which is the VC) has a property of a recipe, like so:
#property (nonatomic, strong) Recipe *recipe;
When I tap the cell, the segue fires, and the error occurs, with the following message from console:
2013-09-25 18:55:21.888 RecipeBank [974:60b] -[UITabBarController setRecipe:]: unrecognized selector sent to instance 0x15da8280
2013-09-25 18:55:21.892 RecipeBank [974:60b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setRecipe:]: unrecognized selector sent to instance 0x15da8280'
First throw call stack:
(0x30583f53 0x3abec6af 0x305878e7 0x305861d3 0x304d5598 0x6676f 0x3319f6f1 0x665b7 0x32e1232b 0x32ec5253 0x32d75971 0x32ced473 0x3054f1d5 0x3054cb79 0x3054cebb 0x304b7ce7 0x304b7acb 0x35185283 0x32d59a41 0x67711 0x3b0f4ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
RecipeTabBarController imports Recipe class in header and TableViewController that's performing segue imports RecipeTabBarController for it as well. So no mistake there.
What could be wrong?
Please help. Thanks.
Sounds like the class of the destination view controller is UITabBarController and not your own class RecipeTabBarController. Look in your storyboard as to how you have the segue set up and figure out why things are not what you expect.
Related
I'm trying to pass data from my ViewController to TabBarController by using Objective-C. I'm trying to assign some data to "bottomTabEventList" (which is a property of my custom TabBarController class). Unfortunately, my program crashes by giving unrecognized selector instance error/warning.
In custom header of TabBarController class, named BottomTabview:
#interface BottomTabView : UITabBarController <UITabBarControllerDelegate>
#property(strong,nonatomic)EventList *bottomTabEventList;
#end
And prepareForSegue method in ViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
BottomTabView *btw = [segue destinationViewController];
//checking
if(btw == nil)
NSLog(#"btw in viewController is nil");
else
NSLog(#"btw in viewController is NOT nil");
if(self.eventList.eventList == nil)
NSLog(#"eventList in viewController is nil");
else
NSLog(#"eventList in viewController is NOT nil"); //end of checking
btw.bottomTabEventList = self.eventList; //This is where crash appears
}
Exact crash log is:
-[ViewController setBottomTabEventList:]: unrecognized selector sent to instance 0x7fe923c6ba00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController setBottomTabEventList:]: unrecognized selector sent to instance 0x7fe923c6ba00'
Segue is from ViewController to BottomTabView and its type is "Present Modally". I'd really appreciate if you can help/guide me. Thanks in advance.
The problem seems to be that btw is not actually of type BottomTabView and is just a UIViewController hence the crash log giving:
[ViewController setBottomTabEventList:]: unrecognized selector sent to instance
As UIViewController does't know what BottomTabEventList is.
You need to make sure that btw is actually a BottomTabView instance.
Do a little introspection and I bet it will not go into this statement:
if ([btw isKindOfClass:[BottomTabView class]]){
btw.bottomTabEventList = self.eventList;
}
I'm trying to create this application, when you press on a tablecell you get shown the ViewController, and the variable get's set in the other view controller. Although i'm getting a few errors when i press the uitablecell.
Error:
2013-04-06 22:47:25.970 iFSX Guide[1069:907] Called
2013-04-06 22:47:26.009 iFSX Guide[1069:907] -[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390
2013-04-06 22:47:26.016 iFSX Guide[1069:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390'
*** First throw call stack:
(0x319b22a3 0x3964c97f 0x319b5e07 0x319b4531 0x3190bf68 0x33832beb 0x338a837f 0x338548fb 0x33a95619 0x338a79b9 0x338a5fe7 0x339c83ef 0xa22a5 0x3387c28d 0x338fef81 0x322c0277 0x319875df 0x31987291 0x31985f01 0x318f8ebd 0x318f8d49 0x354ba2eb 0x3380e301 0xa19d1 0x39a83b20)
libc++abi.dylib: terminate called throwing an exception
The code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)in dexPath{
NSLog(#"Called");
Aircraft = indexPath.row;
[self performSegueWithIdentifier:#"ToSections" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"ToSections"]){
AirplaneSections *sections = (AirplaneSections *)segue.destinationViewController;
sections.plane = Aircraft;
}
}
I've found out that it's an error on ViewDidLoad on the viewcontroller.
NSString *quickTemp = [NSString alloc];
switch (plane) {
case 0:
quickTemp = #"Boeing 737-800";
break;
default:
break;
}
TitleLabel.text = quickTemp;
*/
I'm doing something wrong there.
Are you using ARC? This sort of problem usually indicates there's a memory error somewhere. Basically, some code somewhere is trying to access an object that was already released. This makes everything go kaboom.
If you aren't using ARC, you should turn it on.
After that, the next thing you should do is run the static analyzer. Fix anything that comes up.
If that doesn't fix the problem, in Xcode, add a breakpoint that stops when an Objective-C exception is thrown. It should show you where exactly this problem is happening.
If that doesn't help, run your code under Instruments' and the Zombie tool. This will show you exactly where you tried to access memory that was already released.
I have everything implemented, and the following method that fires when I return to the source view controller:
- (IBAction)returned:(UIStoryboardSegue *)segue {
...
}
I want to take the value from the UITextField in the view I'm returning from, and set a value in my source view (or the view that calls this method) to the value of that UITextField.
I tried this:
- (IBAction)returned:(UIStoryboardSegue *)segue {
AddTextViewController *returnedFromViewController = segue.destinationViewController;
NSString *inputtedText = returnedFromViewController.textField.text;
self.foo = inputtedText;
}
But I get this error:
[RootViewController textField]: unrecognized selector sent to instance 0x8dc0250
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController textField]: unrecognized selector sent to instance 0x8dc0250'
What am I doing wrong in that code above? There's hardly any documentation on this, so it's very hard to search around myself.
You're using the wrong controller. You want the segue's sourceViewController, not the destinationViewController. Otherwise, you're doing it all correctly.
The best way to do this is to implement a protocol / delegate. The delegate will handle any requests from your destination view controller and send the data back to your source view controller.
http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html
I'm using Action Sheet Picket. I added .h and .m files as instructed in readme, picker and even cancelAction is working well but somehow successAction throws NSInvalidArgumentException with this message: "unrecognized selector sent to instance".
Application is a kind of tab bar application with Navigation Controller. There is a TabBarController as root and there are ViewControllers which are located under the TabBarController and one of the ViewControllers is a Navigation Controller. But I'm not getting this error in Navigation Controller. I'm not sure if this causes any error.
Here how I used:
- (IBAction)filterResult:(id)sender {
[ActionSheetStringPicker showPickerWithTitle:#"Pick Filter" rows:self.filterList initialSelection: self.selectedIndexes target:self successAction:#selector(animalWasSelected:element:) cancelAction:nil origin: self];
}
- (void)animalWasSelected:(NSNumber *)selectedIndex element:(id)element {
self.selectedIndexes = [selectedIndex intValue];
NSLog(#"Selected");
}
Yes that's all. I've already included ActionSheetPicker.h file and as I said picker is working fine.
Finally here is error:
[MYYViewController successAction:]: unrecognized selector sent to instance 0x9032400
2012-12-24 12:14:45.488 Example[54268:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MYYViewController successAction:]: unrecognized selector sent to instance 0x9032400'
Any help would be great.
Looks rather straight forward, you need to implement successAction: in your MYYViewController class, because the picker is not checking if it will respond or not and calling it directly.
I hope someone can help with this.
I have a UITableViewController and want to pass a value to a UIViewController called NewsArticleViewController when the tablecell is selected. I've created a segue from the tablecell to the view controller.
When I call my prepareForSegue method below:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"ShowNewsArticle"])
{
NSIndexPath *indexPath = [self._tableView indexPathForSelectedRow];
NSDictionary *article = [_articles objectAtIndex:indexPath.row];
NSString *articleID = [article valueForKey:#"id"];
NSLog(#"Trying %#", articleID);
NewsArticleViewController *detailViewController = [segue destinationViewController];
detailViewController.articleID = articleID;
}
}
The NSLog shows the NSString value correctly before the error occurs on the last line.
I get the error:
2012-12-11 23:08:41.915 My School[4689:c07] -[UIViewController setArticleID:]: unrecognized selector sent to instance 0x8088140
2012-12-11 23:08:41.916 My School[4689:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setArticleID:]: unrecognized selector sent to instance 0x8088140'
*** First throw call stack:
(0x1800012 0x11c5e7e 0x188b4bd 0x17efbbc 0x17ef94e 0x3ca1 0x554ac7 0x554b54 0x1bc899 0x1bcb3d 0xbc3e83 0x17bf376 0x17bee06 0x17a6a82 0x17a5f44 0x17a5e1b 0x1cc87e3 0x1cc8668 0x10d65c 0x1f4d 0x1e75 0x1)
libc++abi.dylib: terminate called throwing an exception
On the destination view controller, NewsArticleViewController, I have declared this in the header:
#property(strong,nonatomic) id articleID;
And I have synthesized the property in the method. I'm using ARC, I don't know if this is the specific cause but I can't proceed until I sort this out. Thanks.
In your error message, UIViewController is reporting the "unrecognized selector" error. I suspect your storyboard has not specified your custom NewsArticleViewController for this scene. Thus, it's using the default UIViewController which obviously doesn't understand the setArticleID.
Check the "Custom Class" setting for the view controller in Interface Builder:
If the custom class has not specified, it will look like the above screen snapshot. Just fill in the class name.