I'm trying to execute a method using selector with one NSString as parameter and fails. I have seen many questions (and answers) like this and tried most solutions but had no success. Please see code and errors below:
My MainView.m is my view controller and it has a method:
-(void)displayMessageOnTextView:(NSString *)message
{
[tv1 setText:message];
}
And in MainView.h:
#interface MainView : UIViewController {
UITextView *tv1;
}
-(void)displayMessageOnTextView:(NSString *)message;
....
I have another thread which is fired by MainView (this is from MainView.m):
- (void) runTest
{
MyThread *t = [[MyThread alloc] initWithInt:13253];
[t setMainView:self];
[t run];
[t release];
}
and MyThread.m:
#import "MyThread.h"
#import "MainView.h"
#implementation MyThread
MainView *_view;
-(id)initWithInt:(int)someInt{
_view = NULL;
return self;
}
-(void)setMainView:(MainView*)view
{
_view = view;
}
-(int)run{
NSString *s = [NSString stringWithFormat:#"Display on Gui:%d", 1];
[_view performSelectorOnMainThread:#selector(displayMessageOnTextView:message:) withObject:s waitUntilDone:YES];
}
#end
Error:
2011-04-20 02:08:11.553 myApp[22627:207] -[MainView displayMessageOnTextView:message:]: unrecognized selector sent to instance 0x4e383a0
2011-04-20 02:08:11.555 myApp[22627:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainView displayMessageOnTextView:message:]: unrecognized selector sent to instance 0x4e383a0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc55a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f19313 objc_exception_throw + 44
2 CoreFoundation 0x00dc70bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d36966 ___forwarding___ + 966
4 CoreFoundation 0x00d36522 _CF_forwarding_prep_0 + 50
5 Foundation 0x0079e94e __NSThreadPerformPerform + 251
6 CoreFoundation 0x00da68ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
7 CoreFoundation 0x00d0488b __CFRunLoopDoSources0 + 571
8 CoreFoundation 0x00d03d86 __CFRunLoopRun + 470
9 CoreFoundation 0x00d03840 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x00d03761 CFRunLoopRunInMode + 97
11 GraphicsServices 0x00ffd1c4 GSEventRunModal + 217
12 GraphicsServices 0x00ffd289 GSEventRun + 115
13 UIKit 0x00025c93 UIApplicationMain + 1160
14 myApp 0x000024c9 main + 121
15 myApp 0x00002445 start + 53
)
terminate called after throwing an instance of 'NSException'
NOTE:
I'm new to Objective-C (and generally iOS) programming, so any comment regarding coding conventions and best practice will be appreciated (even if not related to my question, but related to my code)
Your method has been declared as
-(void)displayMessageOnTextView:(NSString *)message;
This means that the method name is displayMessageOnTextView: and the corresponding selector is #selector(displayMessageOnTextView:). Note that a method name does not include parameter (variable) names.
In your -run method, change
[_view performSelectorOnMainThread:#selector(displayMessageOnTextView:message:)
withObject:s
waitUntilDone:YES];
to
[_view performSelectorOnMainThread:#selector(displayMessageOnTextView:)
withObject:s
waitUntilDone:YES];
and that runtime error shouldn’t happen again.
For the record, a method declaration corresponding to displayMessageOnTextView:message: would be:
- (void)displayMessageOnTextView:(type1)parameter1 message:(type2)parameter2;
This method:
-(void)displayMessageOnTextView:(NSString *)message
has the selector displayMessageOnTextView:. The name of the parameter itself (message in your case) does not appear in the selector. (This should be sort of intuitive: the name doesn't necessarily appear when you call the method, so it doesn't appear in the selector.) So you need to be using #selector(displayMessageOnTextView:).
Related
UPDATE 2
My app is crashing when presenting it modally after a user taps a button in ViewController1. In my storyboard, I have a standard present modally segue set to pop up the UINavController/UITableViewController containing the UISearchBar. That's failing every time.
However, in my AppDelegate, if I set the window's rootViewController to the same UINavController/UITableViewController, everything works as expected.
For some reason transitioning via segue and then acting the UISearchBar is causing the crash.
UPDATE 1
I'm now receiving the following error when tapping one letter:
2015-02-03 12:23:35.262 Afar D[28348:2740681] -[NSNull length]: unrecognized selector sent to instance 0x10e352ce0
2015-02-03 12:23:40.313 Afar D[28348:2740681] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x10e352ce0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e0a9f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010dd42bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010e0b104d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010e00927c ___forwarding___ + 988
4 CoreFoundation 0x000000010e008e18 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x000000010df89a7b CFStringCompareWithOptionsAndLocale + 219
6 Foundation 0x000000010d6822b7 -[NSString compare:options:range:] + 29
7 UIKit 0x000000010c5f53b4 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 224
8 UIKit 0x000000010c53c12e -[UIResponder(Internal) _keyCommandForEvent:] + 285
9 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
10 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
11 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
12 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
13 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
14 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
15 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
16 UIKit 0x000000010c3d8f0a -[UIApplication _handleKeyUIEvent:] + 126
17 UIKit 0x000000010c5c7fcc -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 66
18 UIKit 0x000000010c75bbb7 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 3611
19 UIKit 0x000000010c75a8e5 -[UIKeyboardLayoutStar touchUp:executionContext:] + 1374
20 UIKit 0x000000010c5d531b __28-[UIKeyboardLayout touchUp:]_block_invoke + 242
21 UIKit 0x000000010cb23914 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
22 UIKit 0x000000010c5d521c -[UIKeyboardLayout touchUp:] + 252
23 UIKit 0x000000010c5d5cc6 -[UIKeyboardLayout touchesEnded:withEvent:] + 319
24 UIKit 0x000000010c40b308 -[UIWindow _sendTouchesForEvent:] + 735
25 UIKit 0x000000010c40bc33 -[UIWindow sendEvent:] + 683
26 UIKit 0x000000010c3d89b1 -[UIApplication sendEvent:] + 246
27 UIKit 0x000000010c3e5a7d _UIApplicationHandleEventFromQueueEvent + 17370
28 UIKit 0x000000010c3c1103 _UIApplicationHandleEventQueue + 1961
29 CoreFoundation 0x000000010dfdf551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x000000010dfd541d __CFRunLoopDoSources0 + 269
31 CoreFoundation 0x000000010dfd4a54 __CFRunLoopRun + 868
32 CoreFoundation 0x000000010dfd4486 CFRunLoopRunSpecific + 470
33 GraphicsServices 0x000000010fc109f0 GSEventRunModal + 161
34 UIKit 0x000000010c3c4420 UIApplicationMain + 1282
35 My App 0x000000010a5e1c63 main + 115
36 libdyld.dylib 0x000000010e75a145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm using iOS8's new UISearchController to manage a UISearchBar for filtering data in a table. If I activate the UISearchBar, the app crashes as soon as I type the first letter (Interestingly, the on-screen keyboard doesn't appear in the Simulator, but I don't think that's related).
In order to narrow things down, I've commented almost everything out of my UIViewController so that the UITableView renders nothing. I've implemented UISearchControllerDelegate and UISearchBarDelegate just so I can log when each method gets called. However, after typing the first letter, I receive no console messages. I don't even know where I could set a breakpoint.
Here's the crash I get:
-[NSNull length]: unrecognized selector sent to instance 0x107602ce0
Note that nowhere in my file am I calling length on anything. Something behind the scenes is, but I can't figure out what.
Here's my code to set up the UISearchController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.definesPresentationContext = true;
self.searchController.hidesNavigationBarDuringPresentation = false;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;
}
By request, here are my delegate methods (implemented just to see if anything gets called after typing the first letter - they don't):
#pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#pragma mark - UISearchControllerDelegate
- (void)didDismissSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)didPresentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)presentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)willDismissSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)willPresentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
NSNull is just a singleton object used to represent null. It is traditionally used to wrap around nil values in containers(arrays and dictionaries) that cannot handle nil entries.
This error often comes up when parsing json and trying to add the result in a collection.
Are you doing something like this in your delegate method(s)?
Edit: Judging by the message you are sending to that NSNull (length), you probably get an "empty" result for a string you asked for and expected not be nil.
After burning an entire day struggling with this, it came down to a totally unrelated problem: a corrupted storyboard.
This SO question recommended finding which scene was corrupt and recreating it. Unfortunately there was no way for me to determine that, so after some trial and error, it ended up being the initial view controller in my storyboard, which happened to be a UINavigationController. I deleted that, added it back in, and everything is golden.
I've been trying to pass variables between view controllers without much luck. I started to work backwards from the problem I was encountering but am now having problems just getting the segue to action.
Whether I perform the segue with identifier method or have it actioning from the button I am using to perform a calculation I get the below error in the debugger.
Any help would be appreciated.
2014-02-14 13:59:58.795 BatteryCalculator[6944:70b] Cannot find executable for CFBundle 0x8dbd110 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
2014-02-14 14:00:00.869 BatteryCalculator[6944:70b] -[DetectorSpacing _setViewDelegate:]: unrecognized selector sent to instance 0x8dd6ff0
2014-02-14 14:00:00.872 BatteryCalculator[6944:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetectorSpacing _setViewDelegate:]: unrecognized selector sent to instance 0x8dd6ff0'
*** First throw call stack:
(
0 CoreFoundation 0x0173d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014c08b6 objc_exception_throw + 44
2 CoreFoundation 0x017da903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172d90b ___forwarding___ + 1019
4 CoreFoundation 0x0172d4ee _CF_forwarding_prep_0 + 14
5 UIKit 0x00347ecc +[UIViewController setViewController:forView:] + 40
6 UIKit 0x00342921 -[UIViewController setView:] + 511
7 Foundation 0x010edd28 _NSSetUsingKeyValueSetter + 133
8 Foundation 0x010ed253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
9 Foundation 0x0114f70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
10 UIKit 0x004d0a15 -[UIRuntimeOutletConnection connect] + 106
11 libobjc.A.dylib 0x014d27d2 -[NSObject performSelector:] + 62
12 CoreFoundation 0x01738b6a -[NSArray makeObjectsPerformSelector:] + 314
13 UIKit 0x004cf56e -[UINib instantiateWithOwner:options:] + 1417
14 UIKit 0x00341605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
15 UIKit 0x00341dad -[UIViewController loadView] + 302
16 UIKit 0x003420ae -[UIViewController loadViewIfRequired] + 78
17 UIKit 0x003425b4 -[UIViewController view] + 35
18 UIKit 0x0035c3e2 -[UINavigationController _startCustomTransition:] + 778
19 UIKit 0x003690c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
20 UIKit 0x00369cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
21 UIKit 0x004a3181 -[UILayoutContainerView layoutSubviews] + 213
22 UIKit 0x0ecdc56f -[UILayoutContainerViewAccessibility(SafeCategory) layoutSubviews] + 50
23 UIKit 0x00299267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
24 libobjc.A.dylib 0x014d281f -[NSObject performSelector:withObject:] + 70
25 QuartzCore 0x03b4b2ea -[CALayer layoutSublayers] + 148
26 QuartzCore 0x03b3f0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
27 QuartzCore 0x03b3ef40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
28 QuartzCore 0x03aa6ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
29 QuartzCore 0x03aa7e71 _ZN2CA11Transaction6commitEv + 393
30 QuartzCore 0x03aa8544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
31 CoreFoundation 0x017054ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
32 CoreFoundation 0x0170541f __CFRunLoopDoObservers + 399
33 CoreFoundation 0x016e3344 __CFRunLoopRun + 1076
34 CoreFoundation 0x016e2ac3 CFRunLoopRunSpecific + 467
35 CoreFoundation 0x016e28db CFRunLoopRunInMode + 123
36 GraphicsServices 0x036e29e2 GSEventRunModal + 192
37 GraphicsServices 0x036e2809 GSEventRun + 104
38 UIKit 0x0022ed3b UIApplicationMain + 1225
39 BatteryCalculator 0x0000582d main + 141
40 libdyld.dylib 0x01d7b70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
At the moment I'm not trying to pass anything, I took that code out temporarily while trying to locate the problem. All I'm doing is calling a segue with identifier and getting the crash. I've also tried just calling the segue from a button on the first view controller but the same error.
When calling the segue with code I was using:
[self performSegueWithIdentifier:#"ResultSegue" sender:sender];
Here is how I pass managedObjectContext between segues
In your class where you will pass the data use prepareForSegue call. (The assumption is this class has a variable called _managedObjectContext which can be passed along to the segue class)
Class to Segue From:
.h file:
#property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;
.m file:
#synthesize managedObjectContext
The call to #synthesize will make the following:
a local variable called _managedObjectContext
a method to getManagedObjectContext
a method to setManagedObjectContext
Additionally add the following method to your class
// Pass on managedObjectContext
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// If the destination VC is able to take the setManagedObjectContext method the current objectContext will be passed along.
if ([segue.destinationViewController respondsToSelector:#selector(setManagedObjectContext:)]) {
[segue.destinationViewController performSelector:#selector(setManagedObjectContext:)
withObject:_managedObjectContext];
} else {
NSLog(#"Segue to controller [%#] that does not support passing managedObjectContext", [segue destinationViewController]);
}
}
Then in my "class" to receive the data I do:
in the .h file i have
#property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;
and in the .m file i have:
#synthesize managedObjectContext;
What this does (with syntehsiation) is make a setManagedObjectContext and getManagedObjectContext call. Upon being about to segue I check to make sure the destinationController will "respond to" this method, if so the data gets set.
clear?
Okay, so I'm trying to embed my entire applications already created using the MasterDetail template inside of a tab controller.
I get an error because the app delegate places the context on the top view controller or something like that and i'm not sure where to redirect it to.
Now, I have searched it and found this: iOS MasterDetail app inside TabController - where to start?
but this isn't particularly helpful because the solution just gives more errors.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
Errorlog:
2013-11-07 07:47:01.217 RoslynCAD[4491:70b] -[UITabBarController topViewController]: unrecognized selector sent to instance 0x9d72fe0
2013-11-07 07:47:01.220 RoslynCAD[4491:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController topViewController]: unrecognized selector sent to instance 0x9d72fe0'
*** First throw call stack:
(
0 CoreFoundation 0x01cf75e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01a7a8b6 objc_exception_throw + 44
2 CoreFoundation 0x01d94903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01ce790b ___forwarding___ + 1019
4 CoreFoundation 0x01ce74ee _CF_forwarding_prep_0 + 14
5 RoslynCAD 0x0000b9f6 -[AppDelegate application:didFinishLaunchingWithOptions:] + 278
6 UIKit 0x007e2355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
7 UIKit 0x007e2b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
8 UIKit 0x007e73a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
9 UIKit 0x007fb87c -[UIApplication handleEvent:withNewEvent:] + 3447
10 UIKit 0x007fbde9 -[UIApplication sendEvent:] + 85
11 UIKit 0x007e9025 _UIApplicationHandleEvent + 736
12 GraphicsServices 0x0262e2f6 _PurpleEventCallback + 776
13 GraphicsServices 0x0262de01 PurpleEventCallback + 46
14 CoreFoundation 0x01c72d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
15 CoreFoundation 0x01c72a9b __CFRunLoopDoSource1 + 523
16 CoreFoundation 0x01c9d77c __CFRunLoopRun + 2156
17 CoreFoundation 0x01c9cac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x01c9c8db CFRunLoopRunInMode + 123
19 UIKit 0x007e6add -[UIApplication _run] + 840
20 UIKit 0x007e8d3b UIApplicationMain + 1225
21 RoslynCAD 0x000147ed main + 141
22 libdyld.dylib 0x0308370d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
and
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
UPDATE:
I have edited my code:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)[tabController.viewControllers objectAtIndex:0];
controller.managedObjectContext = self.managedObjectContext;
And I get this error now
2013-11-10 00:37:03.455 RoslynCAD[6783:70b] -[UINavigationController setManagedObjectContext:]: unrecognized selector sent to instance 0x9e54c40
(lldb)
The error is clear. You are doing this:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
The error comes from the second line. The error is telling you that navigationController is actually a UITabBarController, not a UINavigationController.
You want:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
// Get what you need from the tab controller
This is a followup question to this
In short, I'm making my app iOS 4.3 compatible and using the AFNetworking class version 0.10.1 that supports iOS 4 in my app.
This line self.responseJSON = AFJSONDecode(self.responseData, &error); gives me the error bellow. I'm not really familiar with JSON and trying to figure out what this error means.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** - [JKDictionary allocWithZone:]: The JKDictionary class is private to JSONKit and should not be used in this fashion.'
*** Call stack at first throw:
(
0 CoreFoundation 0x006ef5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018e6313 objc_exception_throw + 44
2 CoreFoundation 0x006a7ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x006a7e6a +[NSException raise:format:] + 58
...
...
26 libdispatch_sim.dylib 0x02888289 _dispatch_call_block_and_release + 16
27 libdispatch_sim.dylib 0x0288acb4 _dispatch_queue_drain + 250
28 libdispatch_sim.dylib 0x0288b2c2 _dispatch_queue_invoke + 49
29 libdispatch_sim.dylib 0x0288b593 _dispatch_worker_thread2 + 261
30 libsystem_c.dylib 0x90093b24 _pthread_wqthread + 346
31 libsystem_c.dylib 0x900956fe start_wqthread + 30
The error is from JSONKit.m:
+ (id)allocWithZone:(NSZone *)zone
{
#pragma unused(zone)
[NSException raise:NSInvalidArgumentException format:#"*** - [%# %#]: The %# class is private to JSONKit and should not be used in this fashion.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSStringFromClass([self class])];
return(NULL);
}
With iOS 5 the app is using the line self.responseJSON =[NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error]; that works great but ofcourse I can't use this in iOS 4 because NSJSONSerialization isn't supported.
I ended up replacing the problematic line with this self.responseJSON = [[CJSONDeserializer deserializer] deserialize:self.responseData error:&error];
Used a different class (TouchJSON) just for that line but it works great now.
I'm making this voice recording app, but for some reason it won't let me use this delete method without crashing:
-(void)deleteCurrentFiles {
if(recorder != nil) {
if([recorder isRecording]) {
[recorder stop];
}
[recorder release];
recorder = nil;
[self performSelector:#selector(resetTotalTimeLabel) withObject:nil afterDelay:1.0];
}
if(player != nil) {
if([player isPlaying]) {
[player stop];
}
[player release];
player = nil;
currentTime = 0;
timeSlider.value = 0;
[self performSelector:#selector(resetCurrentTimeLabel) withObject:nil afterDelay:0.1];
}
if(commentRecorder != nil) {
if([commentRecorder isRecording]) {
[commentRecorder stop];
}
}
}
The declarations of these instances:
AVAudioRecorder *recorder;
AVAudioRecorder *commentRecorder;
AVAudioPlayer *player;
In resetTotalTimeLabel and resetCurrentTimeLabel there is no referance to / usage of the recorders/player.
The error I get is:
-[__NSArrayI finishedRecording]: unrecognized selector sent to instance 0x1b3ba0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI finishedRecording]: unrecognized selector sent to instance 0x1b3ba0'
*** Call stack at first throw:
(
0 CoreFoundation 0x35f08c7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x30186ee8 objc_exception_throw + 40
2 CoreFoundation 0x35f0a3e3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 98
3 CoreFoundation 0x35eaf467 ___forwarding___ + 506
4 CoreFoundation 0x35eaf220 _CF_forwarding_prep_0 + 48
5 CoreFoundation 0x35ea3f79 -[NSObject(NSObject) performSelector:withObject:] + 24
6 Foundation 0x33fd3e6d __NSThreadPerformPerform + 272
7 CoreFoundation 0x35ebc8d1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8 CoreFoundation 0x35e8cecd __CFRunLoopDoSources0 + 384
9 CoreFoundation 0x35e8c6f9 __CFRunLoopRun + 264
10 CoreFoundation 0x35e8c50b CFRunLoopRunSpecific + 226
11 CoreFoundation 0x35e8c419 CFRunLoopRunInMode + 60
12 GraphicsServices 0x35261d24 GSEventRunModal + 196
13 UIKit 0x3386557c -[UIApplication _run] + 588
14 UIKit 0x33862558 UIApplicationMain + 972
15 App Name 0x00002959 main + 80
16 App Name 0x00002904 start + 40
)
terminate called after throwing an instance of 'NSException'
It actually seems to happen to the recorder after this method is called.. So is there anything I should add to this method to make it work?
Any thoughts are greatly appriciated!
sending a message to an object which does not respond to it at a strange point in time is a good indication of a reference count imbalance. run your app with zombies enabled in Instruments. reproduce the crash and see if it is a zombie.