This question already has answers here:
[NSManagedObjectContext delete:]: unrecognized selector sent to instance
(2 answers)
Closed 7 years ago.
I have three controllers, one to display all data, second the view deleted item and third to edit. All works fine besides from deleting the NSManagedObject, currently the app crashes with an error of;
unrecognized selector sent to instance 0x7f945b56a680 2015-08-17
18:35:08.835 AppTest[8008:435289] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason:
'-[NSManagedObjectContext delete:]: unrecognized selector sent to
instance ... terminating with uncaught exception of type NSException
(lldb)
Why is this error occurring and how can I delete a NSManagedObject within the UINavigationController and the popToRootController to segue back to the collection view ?
Heres what I have been trying to do in editViewController;
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
#IBAction func remove(sender: AnyObject) {
context?.delete(self.selectedObject)
var error: NSError?
context?.save(&error)
self.navigationController?.popToRootViewControllerAnimated(true)
}
Update: I was not having a problem using the popToRootViewControllermethod but using the delete method which should have been deleteObject(). Now i know the problem I see there are many questions on it.
You want deleteObject(), not delete(), since delete is an unimplemented extension on NSObject.
Your code should be:
context?.deleteObject(self.selectedObject as NSManagedObject)
Related
I've created a XIB containing only a UITableView. I changed the parameters of the project to load this view at launch. But I get this "unrecognized selector sent to instance" error I don't know what it is. How do I fix this and get my app to show my view ?
I've searched the web and it seems that might come from Objective-C libraries ?
EDIT
I did some testing, it's look like it crashes when I link my TableView with my IBOutlet in the ViewController. Am I doing something wrong with the type TableView ?
The viewcontroller :
class Liste: UIViewController {
#IBOutlet weak var maListe: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
The error stack :
2019-06-12 14:06:11.083905+0200 GuildWar[5905:8796162]
-[GuildWar.Liste _finishDecodingLayoutGuideConnections:]: unrecognized selector sent to instance 0x104f0ef40 2019-06-12 14:06:17.511280+0200
GuildWar[5905:8796162] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[GuildWar.Liste
_finishDecodingLayoutGuideConnections:]: unrecognized selector sent to instance 0x104f0ef40'
* First throw call stack: (0x21230f518 0x2114ea9f8 0x21222c278 0x23e4c2ef8 0x212314d60 0x2123169fc 0x23e874110 0x21c955f28
0x21c8f5304 0x212cdba4c 0x21c955f28 0x21c95616c 0x21c8f5304
0x23e151dcc 0x23e152958 0x23e4971e4 0x23e4977c0 0x23e495e24
0x23dd5a104 0x23dd6269c 0x23dd59d88 0x23dd5a678 0x23dd589c4
0x23dd5868c 0x23dd5d1cc 0x23dd5dfb0 0x23dd5d084 0x23dd61d84
0x23e494518 0x23e090f0c 0x214c89d44 0x214c93754 0x214c92f5c
0x104cbcc74 0x104cc0840 0x214cc40bc 0x214cc3d58 0x214cc4310
0x2122a12bc 0x2122a123c 0x2122a0b24 0x21229ba60 0x21229b354
0x21449b79c 0x23e497b68 0x1045ea10c 0x211d618e0) libc++abi.dylib:
terminating with uncaught exception of type NSException
It looks like, you might have created IBOutlet or IBAction and deleted later in the code. Revisit the connections in the storyboard connection inspectors and check if there is any warning symbol like the attached screenshot, then you need to remove that connection.
Or if you can share your code I can look into.
After migrating to Swift 3, the app crashes on
-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x60800064d5f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x60800064d5f0'
When trying to access vc.view. Here is the relevant code snippet. The code is called from a UIViewController.
guard let vc = storyboard?.instantiateViewController(withIdentifier: "some-viewcontroller-id") else {
return
}
if let vc = vc as? SomeViewController {
let theView: UIView = vc.view
theView.translatesAutoresizingMaskIntoConstraints = false
}
If I stop on breakpoint before calling let theView: UIView = vc.view and po vc.view in the debug window, I get the same error in the debug window.
-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance
BUT if I po vc.view again I get... voilĂ ...
Optional<UIView>
and the execution can be resumed. I am using Xcode 8.1. Reproduces both on iOS device and simulator.
Any suggestions?
I think it's not due to UIViewController.view. Your error says that it's Unrecognized Selector send to instance allocating at some kind of memory index. If one of ur selector method is private, put #objc in front of it. I can surely say it's not the Nil value error.
Make the storyboard-id of the view as "some-viewcontroller-id"
and it would work fine
ISSUE RESOLVED
To make a long story short, it is not related to UIViewController.view at all! It is related to the String.Encoding.utf8.rawValue issue described in this answer.
For some reason the crash on simulator didn't give much info except for I already pasted into the question. On device, it produced a much detailed report that helped me find the root cause of this crash.
if([segue.identifier isEqualToString:#"CatagoryToSets"]){
BYFSetsViewController *controller = (BYFSetsViewController *)segue.destinationViewController;
//throw exception when i try to set them
controller.workOut.catagory = catagory.text;//<<UITextfield
controller.workOut.excercise = excercize.text;
NSLog(#"passing the values %# \n and %# ",catagory.text,excercize.text);
}
Im trying to pass data to the next view BYFSetsViewController WorkOut is a object that i created and has two NSStrings that i want the user to enter then pass to the next view
But i keep getting the error that it cannot write to that adress
the error message i get is
2014-03-20 19:31:11.423 Gym_Log_Book[25611:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController workOut]: unrecognized selector sent to instance 0x8d698c0'
any help would be appreciated
#import <QuartzCore/QuartzCore.h>
- (void)viewDidLoad
{
[self.forwardView setFrame:CGRectMake(12.0, 40.0+height, 296.0, rootViewHeight-15.0)];
self.forwardView.layer.borderColor = [UIColor colorWithRed:153.0/250.0 green:153.0/250.0 blue:153.0/250.0 alpha:100].CGColor;
self.forwardView.layer.borderWidth = 1;
CGRect frame = CGRectMake(12.0f, 40.0f, 288.0f , height);
[self.tvContent setFrame:frame];
}
[self.tvContent setFrame:frame]; //crash?
Exception message:
-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x7894c00
2013-05-21 10:44:54.677 Sohappy[22295:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x7894c00'
*** First throw call stack:
(0x1eb5012 0x19aae7e 0x1f404bd 0x1ea4bbc 0x1ea494e 0xfb407 0xfc20b 0x9d01c7 0x9d0232 0x9d04da 0x9e78e5 0x9e79cb 0x9e7c76 0x9e7d71 0x9e889b 0x9e8e93 0x8ef13f7 0x9e8a88 0x93b9 0x99df83 0x99e4ed 0x13a85b3 0x1e74376 0x1e73e06 0x1e5ba82 0x1e5af44 0x1e5ae1b 0x24e27e3 0x24e2668 0x8eeffc 0x2acd 0x29f5 0x1)
libc++abi.dylib: terminate called throwing an exception
UILabel in .xib , UseAutoLayout, ios sdk 6.1
You are trying to set the frame of an NSString - something that doesn't exist. self.tvContent is an NSString, not a UILabel as you seem to have suspected.
This is a good chance to learn how to read exceptions. I'll break it down for you here:
-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x7894c00
2013-05-21 10:44:54.677 Sohappy[22295:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x7894c00'
*** First throw call stack:
(0x1eb5012 0x19aae7e 0x1f404bd 0x1ea4bbc 0x1ea494e 0xfb407 0xfc20b 0x9d01c7 0x9d0232 0x9d04da 0x9e78e5 0x9e79cb 0x9e7c76 0x9e7d71 0x9e889b 0x9e8e93 0x8ef13f7 0x9e8a88 0x93b9 0x99df83 0x99e4ed 0x13a85b3 0x1e74376 0x1e73e06 0x1e5ba82 0x1e5af44 0x1e5ae1b 0x24e27e3 0x24e2668 0x8eeffc 0x2acd 0x29f5 0x1)
libc++abi.dylib: terminate called throwing an exception
Here's what you are interested in:
-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x7894c00
The system is giving you the class of the object and the message you tried to send it - in this case an NSString that you tried to call setFrame: on.
This information coupled with that you know which line is crashing makes for an easy conclusion: self.tvContent is an NSString where you were probably expecting a UILabel.
-[__NSCFString setFrame:]
Your app thinks that tvContent is a string, not a view. Make sure your outlet is connected to your UI correctly. Additionally, if you have a property for tvContent, it needs to be an owning reference (eg strong (under ARC) or retain (non-ARC)).
I have been spending days to make connection from a button on the storyboard to a new NSObject class in an IOS project. Methods I used in OS X no longer work in IOS.
I have no trouble connection the button to the IBAction on the original UIViewController class. According to the Apple documentation my new class is not a "valid connection destination".
To work around the issue I tried to call the method in the new class from the UIViewController class. I tried notification and delegate schemes, using the posts on Stack Overflow, but could not get them to work.
The closest I came linking to a +method in the target class, such as
+ (void) startToneGenerator
{
NSLog(#"Arrived in startToneGenerator");
// [self startPlay:nil];
}
However, from inside that method I can not call the -startPlay in the same class. Because the -StartPlay class is part of an audio unit construct I can not change it to a +starPlay class without breaking the audio unit.
Can anyone point me to some documentation which describes what "valid connection destination" really means, and how to make the attempted connection a valid one.
I used the method suggested in answer 1 in OS X, where it does work, but it no longer works in IOS.
I am restating the code you clarify the problem.
// code in VC
- (IBAction)RunPauseStop:(id)sender
{
NSLog(#"arrived in RunPauseSTop"); // OK
[uToneGenerator testMethod]; // OK
// [uToneGenerator startPlay:self]; // crashes
}
// code in uToneGenerator
+ (void) testMethod
{
NSLog(#"arrived in <testMethod>"); // OK
// [uToneGenerator startPlay:nil]; // crashes
}
- (IBAction)startPlay:(id)sender
{
NSLog(#"arrived in <startPlay>"); // Don't get here
}
The line [uToneGenerator startPlay:nil]; compiles (with a warning) but crashes with:
2012-03-06 13:20:25.509 Tinnitus Tamer IP[863:f803] +[uToneGenerator startPlay:]: unrecognized selector sent to class 0x6c40
2012-03-06 13:20:25.509 Tinnitus Tamer IP[863:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[uToneGenerator startPlay:]: unrecognized selector sent to class 0x6c40'
calling from testMethod; compiles but crashes with:
2012-03-06 13:22:31.413 Tinnitus Tamer IP[885:f803] +[uToneGenerator startPlay:]: unrecognized selector sent to class 0x6c44
2012-03-06 13:22:31.414 Tinnitus Tamer IP[885:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[uToneGenerator startPlay:]: unrecognized selector sent to class 0x6c44'
I noted that the error message can not find +[uToneGenerator startPlay:, but the method I am trying to call is -[uToneGenerator startPlay:
uToneGenerator *utg = [[uToneGenerator alloc]init]; works OK. In spite of the compiler warning "NSProject may not respond to 'startPlay'.
Thanks for helping me out. Much appreciated. I really was stuck.
You need to call whatever class method you want inside the IBAction method in your VC:
- (IBAction)myButtonPressed:(id)sender {
[MyClass myClassMethod];
}
If you want that code to work you must declare - (IBAction)startPlay:(id)sender with a +. Otherwise you will have to make an instance of your class:
uToneGenerator *utg = [[uToneGenerator alloc]init]; //or whatever you use
and then use that to call your startPlay method:
[utg startPlay:self];
Hope it helps.