xcode crashing for using Key I never called - ios

So my application is crashing here:
- (void)showMenu
{
MenuViewController *menuVC = [[MenuViewController alloc] initWithStyle:UITableViewStylePlain];
NSLog(#"between the two things");
[self.navigationController pushViewController:menuVC animated:YES];
NSLog(#"after it was pushed");
}
The first NSLog works, but the second doesn't. I have an identical showSettings function so the error is supposedly in MenuViewController. The error I am getting says:
2013-09-22 02:12:05.308 Mhacks[13947:c07] *** Terminating app due to uncaught exception'
NSUnknownKeyException', reason: '[<MenuViewController 0xc3c6600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key rearTableView.']
*** First throw call stack:
(0x1c98012 0x10d5e7e 0x1d20fb1 0xb81e41 0xb035f8 0xb030e7 0xb2db58 0x237019 0x10e9663 0x1c9345a 0x235b1c 0xfa7e7 0xfadc8 0x24928e 0xfaff8 0xfb232 0xfb4da 0x1128e5 0x1129cb 0x112c76 0x112d71 0x11389b 0x113e93 0x113a88 0x28c3 0x10e9705 0x1d2c0 0x1d258 0xde021 0xde57f 0xdd6e8 0x4ccef 0x4cf02 0x2ad4a 0x1c698 0x1bf3df9 0x1bf3ad0 0x1c0dbf5 0x1c0d962 0x1c3ebb6 0x1c3df44 0x1c3de1b 0x1bf27e3 0x1bf2668 0x19ffc 0x1d0d 0x1c35 0x1)
libc++abi.dylib: terminate called throwing an exception
I have searched the project and "rearTableView" isn't used anywhere (I used it at some point but I deleted that class and everything that had to do with it)
I've also Cleaned my project multiple times. Does anyone have any idea what's going on? Thanks!

You likely still have a reference to rearTableView in a nib. Open the relevant nib, select File's Owner, and check the Connections inspector. If you see rearTableView there, remove it with the x button.

Related

UIViewController throws 'unrecognized selector' error

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, crash on accessing ViewController's view

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.

NSInvalidArgumentException - XCode 6.0.1

I realize this error has been discussed many times on stackoverflow, but I'm still not sure what I'm missing. Here's the console output:
Unknown class CRBarGraphController in Interface Builder file.
2014-11-18 18:40:05.796 Test[7319:60b] -[UIImageView start2]: unrecognized selector sent to instance 0x16562ac0
2014-11-18 18:40:06.256 Test[7319:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView start2]: unrecognized selector sent to instance 0x16562ac0'
CRBarGraphController.m defines a function (void)start2; also declared in the interface for CRBarGraphController.h.
start2 is called from CRGraphViewController.m using the following code:
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden = NO;
[self.bar_Graph start2];
}
where, bar_Graph is an object of CRBarGraphController, declared in CRGraphViewController.h as:
#property (weak, nonatomic) IBOutlet CRBarGraphController *bar_Graph;
CRGraphViewController.h does import CRBarGraphController.h
Also, in the storyboard, bar_Graph outlet is set to class, CRBarGraphController.
Why does XCode still think bar_Graph is an instance of UIImageView and not CRBarGraphComtroller? I included an exception breakpoint to make sure the exception originates from where start2 is being called.

GenericException : Collection was mutated while being enumerated

I have searched for this problem and I know it is caused because an array is manipulated while its enumeration. Earlier in my code, I was using :
-(BOOL)busy
{
for(DataRequest* request in self.active)
if(!request.invisible)
return YES;
return NO;
}
and -(BOOL)busy is being called very frequently as the data loads from the server. Also in my code I have some lines which adds and removes objects in self.active. And because of this I was getting the exception. Then I made a change in the code as:
-(BOOL)busy
{
self.tempActive = self.active;
for(DataRequest* request in _tempActive)
if(!request.invisible)
return YES;
return NO;
}
but I am still getting the same exception. What am I doing wrong, any ideas? This is the only code where self.tempActive is used.
The exception I am getting is:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x9ec8f60> was mutated while being enumerated.'
You need to understand the difference between classes and stack objects (like ints and things). Setting something equal to something else does not make a copy of it if it is a class. You need to use [self.active copy] instead.

Connect to an IOS IBAction which is not at a "valid connection destination"

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.

Resources