Application crash on UIButton click : iphone - objective-c

I have a View base iphone application
I add a NSObject class AddNewContact and take its object in IB
AddNewContact.h
#import <Foundation/Foundation.h>
#interface AddNewContact : NSObject {
}
-(IBAction)abc:(id)sender;
#end
AddNewContact.m
#import "AddNewContact.h"
#implementation AddNewContact
-(IBAction)abc:(id)sender{
NSLog(#"this is test");
}
#end
I bind a UIButton action to abc: on clicking the button application crashes, even NSLog is also not logged
but if I bind the button action to other classes function then it working ok
Crash Log
2011-06-08 15:40:30.368 myApp[5466:207] -[NSCFString abc:]: unrecognized selector sent to instance 0x6b7b1c0
2011-06-08 15:40:30.416 myApp[5466:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString abc:]: unrecognized selector sent to instance 0x6b7b1c0'
*** Call stack at first throw:
(
0 CoreFoundation 0x02ad9b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02c2940e objc_exception_throw + 47
2 CoreFoundation 0x02adb6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02a4b2b6 ___forwarding___ + 966
4 CoreFoundation 0x02a4ae72 _CF_forwarding_prep_0 + 50
5 UIKit 0x0039e7f8 -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x00429de0 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0042c262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x0042ae0f -[UIControl touchesEnded:withEvent:] + 458
9 UIKit 0x003c23d0 -[UIWindow _sendTouchesForEvent:] + 567
10 UIKit 0x003a3cb4 -[UIApplication sendEvent:] + 447
11 UIKit 0x003a89bf _UIApplicationHandleEvent + 7672
12 GraphicsServices 0x0306a822 PurpleEventCallback + 1550
13 CoreFoundation 0x02abaff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x02a1b807 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x02a18a93 __CFRunLoopRun + 979
16 CoreFoundation 0x02a18350 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x02a18271 CFRunLoopRunInMode + 97
18 GraphicsServices 0x0306900c GSEventRunModal + 217
19 GraphicsServices 0x030690d1 GSEventRun + 115
20 UIKit 0x003acaf2 UIApplicationMain + 1160
21 myApp 0x00001fa4 main + 102
22 myApp 0x00001f35 start + 53
)
terminate called after throwing an instance of 'NSException'
Can anybody tell me where I am wrong
Thanks
Amit Battan

You will be releasing your AddNewContact view controller, the view is still in the superview but the viewController is released, the button tries to call 'abc' on AddNewContact controller which no longer exists...

Related

sorting an NSMutableArray of objects in cocoa gives SIGABRT

I am creating a program that requires me to build an NSMutable array and then add objects to that array as buttons are clicked.
After the user has clicked all the buttons that they want (therefore adding all the objects that they need into the mutable array) I need to sort the array based on the objects name.
The objects are NSImageViews that are added to the array with names like view1, view2, view40.
I need a way to sort the objects in the array according to the numbers in the last digit of their name.
I was using
[nameOfArray sortUsingSelector:#selector(caseInsensitiveCompare:)];
but when I run the app I get SIGABRT at that line.
I have looked at many many other threads and can not find a solution.
Any help is greatly appreciated, as I have been working on this for several weeks now,
Anybody know what I am doing wrong?
EDIT , Here is what the debugger said afterwords
2011-09-30 08:16:06.669 CAP helper[9874:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView caseInsensitiveCompare:]: unrecognized selector sent to instance 0x4e5f650'
*** Call stack at first throw:
(
0 CoreFoundation 0x00de05a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f34313 objc_exception_throw + 44
2 CoreFoundation 0x00de20bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d51966 ___forwarding___ + 966
4 CoreFoundation 0x00d51522 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x00d472f6 __CFSimpleMergeSort + 374
6 CoreFoundation 0x00d4706c CFSortIndexes + 268
7 CoreFoundation 0x00dda642 -[NSMutableArray sortRange:options:usingComparator:] + 274
8 CoreFoundation 0x00d598cf -[NSMutableArray sortWithOptions:usingComparator:] + 95
9 CoreFoundation 0x00d5983c -[NSMutableArray sortUsingSelector:] + 108
10 CAP helper 0x0000cf81 -[RibbonStacker stackit:] + 305
11 UIKit 0x000324fd -[UIApplication sendAction:to:from:forEvent:] + 119
12 UIKit 0x000c2799 -[UIControl sendAction:to:forEvent:] + 67
13 UIKit 0x000c4c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
14 UIKit 0x000c37d8 -[UIControl touchesEnded:withEvent:] + 458
15 UIKit 0x00056ded -[UIWindow _sendTouchesForEvent:] + 567
16 UIKit 0x00037c37 -[UIApplication sendEvent:] + 447
17 UIKit 0x0003cf2e _UIApplicationHandleEvent + 7576
18 GraphicsServices 0x01019992 PurpleEventCallback + 1550
19 CoreFoundation 0x00dc1944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
20 CoreFoundation 0x00d21cf7 __CFRunLoopDoSource1 + 215
21 CoreFoundation 0x00d1ef83 __CFRunLoopRun + 979
22 CoreFoundation 0x00d1e840 CFRunLoopRunSpecific + 208
23 CoreFoundation 0x00d1e761 CFRunLoopRunInMode + 97
24 GraphicsServices 0x010181c4 GSEventRunModal + 217
25 GraphicsServices 0x01018289 GSEventRun + 115
26 UIKit 0x00040c93 UIApplicationMain + 1160
27 CAP helper 0x00002219 main + 121
28 CAP helper 0x00002195 start + 53
29 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception
Current language: auto; currently objective-c>
Your array contains UIImageViews and your sort calls caseInsensitiveCompare: on those instances of UIImageView, but that class doesn't have any method by that name. You should do something like this:
[nameOfArray sortUsingComparator:^(id obj1, id obj2) {
UIImageView *view1 = obj1;
UIImageView *view2 = obj2;
// Somehow compare the views and return NSOrderedAscending,
// NSOrderedDescending or NSOrderedSame, for example by calling
// appropriate "compare:" methods.
return myComparisonResult
}];

Bizarre key-value coding error for basic UILabel

This is a new one. I'm testing that my various viewcontrollers are getting loaded by my tab bar, so I put this on one of them:
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel*yo=[[UILabel alloc] init];
self.testlabel=yo;
self.testlabel.text=[NSString stringWithFormat:#"sup"];
[yo release];
This is what I get when I click the tab button for that controller:
2011-07-26 14:05:37.773 Pickers[802:707] Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key testlabel.'*
What in the world?! I must be doing something exceptionally basic and wrong here. Can anyone spot it?
I've got this in the .h and .m:
#interface SingleVC : UIViewController
#property (nonatomic, retain) IBOutlet UILabel*testlabel;
#end
and
#implementation SingleVC
#synthesize testlabel;
I get the following stack errors (which I do not know how to read):
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f16313 objc_exception_throw + 44
2 CoreFoundation 0x00dc24e1 -[NSException raise] + 17
3 Foundation 0x00794677 _NSSetUsingKeyValueSetter + 135
4 Foundation 0x007945e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x0021030c -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x00d388cf -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x0020ed23 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x00210ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x000c6628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
10 UIKit 0x000c4134 -[UIViewController loadView] + 120
11 UIKit 0x000c400e -[UIViewController view] + 56
12 UIKit 0x000d6f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
13 UIKit 0x000d5aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
14 UIKit 0x000d78a2 -[UITabBarController _setSelectedViewController:] + 263
15 UIKit 0x000d7711 -[UITabBarController _tabBarItemClicked:] + 352
16 UIKit 0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
17 UIKit 0x00216ce6 -[UITabBar _sendAction:withEvent:] + 422
18 UIKit 0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
19 UIKit 0x000a4799 -[UIControl sendAction:to:forEvent:] + 67
20 UIKit 0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
21 UIKit 0x000a4750 -[UIControl sendActionsForControlEvents:] + 49
22 UIKit 0x000144fd -[UIApplication sendAction:to:from:forEvent:] + 119
23 UIKit 0x000a4799 -[UIControl sendAction:to:forEvent:] + 67
24 UIKit 0x000a6c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
25 UIKit 0x000a57d8 -[UIControl touchesEnded:withEvent:] + 458
26 UIKit 0x00038ded -[UIWindow _sendTouchesForEvent:] + 567
27 UIKit 0x00019c37 -[UIApplication sendEvent:] + 447
28 UIKit 0x0001ef2e _UIApplicationHandleEvent + 7576
29 GraphicsServices 0x00ffb992 PurpleEventCallback + 1550
30 CoreFoundation 0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
31 CoreFoundation 0x00d03cf7 __CFRunLoopDoSource1 + 215
32 CoreFoundation 0x00d00f83 __CFRunLoopRun + 979
33 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
34 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
35 GraphicsServices 0x00ffa1c4 GSEventRunModal + 217
36 GraphicsServices 0x00ffa289 GSEventRun + 115
37 UIKit 0x00022c93 UIApplicationMain + 1160
38 Pickers 0x000025c9 main + 121
39 Pickers 0x00002545 start + 53
)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
kill
quit
So after some Googling on other sites, it turns out that quite a few people have had this exact same and basic problem. I found the solution here:
https://discussions.apple.com/thread/1598422?threadID=1598422
I was checking my classes within the individual nibs of each controller, but you must also set the classes in the tab controller as well, for each item (I had already set the nib name for each tab bar item, but not the class).
so, problem resolved and was, as expected, quite basic.
It's a stumper why the error created was for key value coding, though.
perhaps a connection in IB from some object that formerly had an IBOutlet called testlabel?
stop the debugger in ObjC Exceptions and post your stack trace if it's not obvious

Weird problems with program and debugger in xcode

Okay, I have a program that I'm trying to test on my iPad. I have it all set up so that the app is able to get on the iPad just fine, but running it on the iPad is a different story.
Now, the thing is, my program was working fine on the debug configuration, but now it won't work on that, either. It's strange, because before I was able to get to a certain part of the program before it crashed, but now it's crashing before that.
The debugger is hardly helping. When I use the debugger window, it will step into one line of code, and then suddenly jump back to another line of code.
I really don't understand what's going on. The crash is now occuring in a root view controller that I have set up, called 'FunctionMachineViewController. Here's the code for when it crashes:
-(IBAction)startOnePlayer:(id)sender
{
GameViewController* GameView = [[GameViewController alloc] initWithNibName:nil bundle:nil];
[GameView isOnePlayer:YES withLevel:startLevelNumber];
[self presentModalViewController:GameView animated:YES];
}
GameViewController is supposed to initialize just fine, but the debugger shows it as uninitialized. I even tried setting it up in the header file instead, but the problem still happens. Has anyone else come across these problems? Any help would be greatly appreciated!
EDIT: Here's what the console says when it crashes:
[Session started at 2011-06-02 21:46:10 -0700.]
2011-06-02 21:46:13.309 FunctionMachine[5033:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<GameViewController 0x4b2a890> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Yminus2.'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dd55a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f29313 objc_exception_throw + 44
2 CoreFoundation 0x00dd54e1 -[NSException raise] + 17
3 Foundation 0x0003d677 _NSSetUsingKeyValueSetter + 135
4 Foundation 0x0003d5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x004c130c -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x00d4b8cf -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x004bfd23 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x004c1ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x00377628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
10 UIKit 0x00375134 -[UIViewController loadView] + 120
11 UIKit 0x0037500e -[UIViewController view] + 56
12 UIKit 0x00376a3d -[UIViewController viewControllerForRotation] + 63
13 UIKit 0x00372988 -[UIViewController _visibleView] + 90
14 UIKit 0x0061493c -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 354
15 UIKit 0x002ec81e -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 954
16 UIKit 0x00574619 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1381
17 UIKit 0x0037965d -[UIViewController presentModalViewController:withTransition:] + 3478
18 FunctionMachine 0x00001fdd -[FunctionMachineViewController startOnePlayer:] + 227
19 UIKit 0x002c54fd -[UIApplication sendAction:to:from:forEvent:] + 119
20 UIKit 0x00355799 -[UIControl sendAction:to:forEvent:] + 67
21 UIKit 0x00357c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
22 UIKit 0x00356a1c -[UIControl touchesBegan:withEvent:] + 277
23 UIKit 0x002e9d41 -[UIWindow _sendTouchesForEvent:] + 395
24 UIKit 0x002cac37 -[UIApplication sendEvent:] + 447
25 UIKit 0x002cff2e _UIApplicationHandleEvent + 7576
26 GraphicsServices 0x0172d992 PurpleEventCallback + 1550
27 CoreFoundation 0x00db6944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
28 CoreFoundation 0x00d16cf7 __CFRunLoopDoSource1 + 215
29 CoreFoundation 0x00d13f83 __CFRunLoopRun + 979
30 CoreFoundation 0x00d13840 CFRunLoopRunSpecific + 208
31 CoreFoundation 0x00d13761 CFRunLoopRunInMode + 97
32 GraphicsServices 0x0172c1c4 GSEventRunModal + 217
33 GraphicsServices 0x0172c289 GSEventRun + 115
34 UIKit 0x002d3c93 UIApplicationMain + 1160
35 FunctionMachine 0x00001c64 main + 102
36 FunctionMachine 0x00001bf5 start + 53
37 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Turns out that, when I went and changed the name of several UILabels in the header of GameViewController, I forgot to fix the names in the interface builder, too. Don't know if that was what was causing the debugger to act weird, but everything is working now!

I'm wondering how to add the #synthesize statements for the MovieEditorViewController header file in XCode

The implementation file looks like this:
#import "MovieViewController.h"
#import "Movie.h"
#import "MovieEditorViewController.h"
#implementation MovieViewController
#synthesize titleLabel;
#synthesize boxOfficeGrossLabel;
#synthesize summaryLabel;
#synthesize movie;
but i'm thinking my problem is not adding #synthesize statements for the MovieEditorViewController header file. If it's not this then I've included the debugging log below.
I'm really new to programming and I really can't seem to figure out whats going wrong. When I run the iOS simulator and click the button to display editable text fields the program terminates and goes back to the homescreen. The debugger shows as follows:
[Session started at 2011-06-04
13:00:00 +0100.] 2011-06-04
13:00:05.568 Movie[6678:207]
-[MovieViewController editingViewController]: unrecognized
selector sent to instance 0x8a3bd10
2011-06-04 13:00:05.572
Movie[6678:207] * Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:
'-[MovieViewController
editingViewController]: unrecognized
selector sent to instance 0x8a3bd10'
* Call stack at first throw: ( 0 CoreFoundation
0x00dc95a9 exceptionPreprocess + 185
1 libobjc.A.dylib
0x00f1d313 objc_exception_throw + 44
2 CoreFoundation
0x00dcb0bb -[NSObject(NSObject)
doesNotRecognizeSelector:] + 187 3
CoreFoundation
0x00d3a966 __forwarding + 966 4
CoreFoundation
0x00d3a522 _CF_forwarding_prep_0 + 50
5 Movie
0x000021b4 -[MovieViewController edit]
+ 62 6 UIKit 0x002b94fd -[UIApplication
sendAction:to:from:forEvent:] + 119 7
UIKit
0x00349799 -[UIControl
sendAction:to:forEvent:] + 67 8
UIKit
0x0034bc2b -[UIControl(Internal)
_sendActionsForEvents:withEvent:] + 527 9 UIKit
0x0034a7d8 -[UIControl
touchesEnded:withEvent:] + 458 10
UIKit
0x002ddded -[UIWindow
_sendTouchesForEvent:] + 567 11 UIKit
0x002bec37 -[UIApplication sendEvent:]
+ 447 12 UIKit 0x002c3f2e _UIApplicationHandleEvent +
7576 13 GraphicsServices
0x01721992 PurpleEventCallback + 1550
14 CoreFoundation
0x00daa944
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 52 15 CoreFoundation 0x00d0acf7 __CFRunLoopDoSource1 + 215
16 CoreFoundation
0x00d07f83 __CFRunLoopRun + 979 17
CoreFoundation
0x00d07840 CFRunLoopRunSpecific + 208
18 CoreFoundation
0x00d07761 CFRunLoopRunInMode + 97 19
GraphicsServices
0x017201c4 GSEventRunModal + 217 20
GraphicsServices
0x01720289 GSEventRun + 115 21 UIKit
0x002c7c93 UIApplicationMain + 1160
22 Movie
0x00001b40 main + 102 23 Movie
0x00001ad1 start + 53 24 ???
0x00000001 0x0 + 1 ) terminate called
after throwing an instance of
'NSException'
If anyone could point me in the right direction i'd be very grateful...
Thanks!
Looks like you're in the iPhone SDK Development book. Have you made it to section 4.8 yet? The error says that your MovieViewController doesn't have a property named editingViewController, which is something you add in 4.8. The project won't build and run until you get through section 4.9, which is where you make some connections.

terminate called after throwing an instance of 'NSException' error

Can you please help me, my application worked well, but when i did a modification on it, (i don't remember what kind of modification) i got this message in the console:
[Session started at 2010-11-21 17:15:36 -0500.]
2010-11-21 17:15:37.472 ITMFR[3942:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UICustomObject 0x6a50d90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key window.'
*** Call stack at first throw:
(
0 CoreFoundation 0x021f2b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0234240e objc_exception_throw + 47
2 CoreFoundation 0x021f2ad1 -[NSException raise] + 17
3 Foundation 0x000320f3 _NSSetUsingKeyValueSetter + 135
4 Foundation 0x00032061 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x004b070a -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x02168d0f -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x004af121 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x004b0eb5 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x002bc402 -[UIApplication _loadMainNibFile] + 172
10 UIKit 0x002bd31c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 198
11 UIKit 0x002c73ec -[UIApplication handleEvent:withNewEvent:] + 1958
12 UIKit 0x002bfb3c -[UIApplication sendEvent:] + 71
13 UIKit 0x002c49bf _UIApplicationHandleEvent + 7672
14 GraphicsServices 0x02ad2822 PurpleEventCallback + 1550
15 CoreFoundation 0x021d3ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x02134807 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x02131a93 __CFRunLoopRun + 979
18 CoreFoundation 0x02131350 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x02131271 CFRunLoopRunInMode + 97
20 UIKit 0x002bcc6d -[UIApplication _run] + 625
21 UIKit 0x002c8af2 UIApplicationMain + 1160
22 ITMFR 0x00003eb8 main + 102
23 ITMFR 0x000028e9 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
please, HELP ME!!
From the crash report, I would guess that the change you made was to the nib / xib file in Interface builder, specifically in binding a value to a button / control. Check the Inspector for all of your UI controls to make sure that any Button Bindings that are bound to Shared User Defaults Controller have controller key values, and not something else.
This happened to me because I forgot #synthesize.
#synthesize window;
In my view controller.