iPad Simulator Crashing, "NSInvalidArgumentException" [duplicate] - objective-c

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
crashing on ios device while navigation using UIModalTransitionStylePartialCurl in xcode 4
HI I am making an app which is a test, halfway through the middle, i run, and i get a crash in my switching page code, this never happened before, suddenly it happened. weird right? This is my code:
-(IBAction)fail {
Fail *fail = [[Fail alloc]
initWithNibName:#"Fail" bundle:nil];
fail.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:fail animated:YES];
}
Here is my console crash log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nested modal view controller while curled <QThree: 0x5537190>.'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f025a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01056313 objc_exception_throw + 44
2 UIKit 0x000d2bac -[UIViewController presentModalViewController:withTransition:] + 741
3 Smart2 0x0000730a -[QThree fail] + 135
4 UIKit 0x0001f4fd -[UIApplication sendAction:to:from:forEvent:] + 119
5 UIKit 0x000af799 -[UIControl sendAction:to:forEvent:] + 67
6 UIKit 0x000b1c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
7 UIKit 0x000b07d8 -[UIControl touchesEnded:withEvent:] + 458
8 UIKit 0x00043ded -[UIWindow _sendTouchesForEvent:] + 567
9 UIKit 0x00024c37 -[UIApplication sendEvent:] + 447
10 UIKit 0x00029f2e _UIApplicationHandleEvent + 7576
11 GraphicsServices 0x0113b992 PurpleEventCallback + 1550
12 CoreFoundation 0x00ee3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
13 CoreFoundation 0x00e43cf7 __CFRunLoopDoSource1 + 215
14 CoreFoundation 0x00e40f83 __CFRunLoopRun + 979
15 CoreFoundation 0x00e40840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00e40761 CFRunLoopRunInMode + 97
17 GraphicsServices 0x0113a1c4 GSEventRunModal + 217
18 GraphicsServices 0x0113a289 GSEventRun + 115
19 UIKit 0x0002dc93 UIApplicationMain + 1160
20 Smart2 0x00003092 main + 83
21 Smart2 0x00002911 start + 53
)
terminate called after throwing an instance of 'NSException'
I have no idea what the problem is, especially why it suddenly rose up in one build, i cant remember which code i added because its actually been a while since i last built. SOO!

You have already presented a view modally with a page curl effect, according to the 'crash'. Unlike other modal presentations, page curl modal view controllers cannot be stacked. Therefore, this exception is being raised as this is what you are trying to do; present a modal view controller inside another modal view controller with a page curl effect.
To stop this, you are going to have to refactor your app workflow or present the first modal view controller with a different animation.

It appears as though you've presented a view with style UIModalTransitionStylePartialCurl. You can't present another modal view after that, you have to dismiss the curled view first.

Related

Assertion failure in [CustomNavigationController popToViewController:transition:]

I want to pop view controllers until the desired view controller is at the top of the navigation stack.
I'm doing it this way:
UIViewController *aViewController = [self.navigationController.viewControllers objectAtIndex:lViewControllerIndex];
[self.navigationController popToViewController:aViewController
animated:YES];
From the debugger I can see that aViewController is <MainViewController: 0x79ea3b10>
and self.navigationController.viewControllers is
<MainViewController: 0x79ea3b10>,
<FirstViewController: 0x79eb2630>,
<SecondViewController: 0x7b258f10>
Currently I'm in SecondViewController and I want to go back to MainViewController
But it crashes, the crash message is the following:
***** Assertion failure in -[CustomNavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-2935.137/UINavigationController.m:4912**
How can I correctly go back by popping multiple view controller ?
UPDATED [1]:
I was not clear, I don't need a way how to pop to root view controller, I need a way how to pop multiple view controllers. Above, it was only an example going from SecondViewController to MainViewController
UPDATED [2]:
Stack trace:
0 CoreFoundation 0x030a81e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02e218e5 objc_exception_throw + 44
2 CoreFoundation 0x030a8048 +[NSException raise:format:arguments:] + 136
3 Foundation 0x00c7d4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x01a45ab8 -[UINavigationController popToViewController:transition:] + 918
5 UIKit 0x01a4571d -[UINavigationController popToViewController:animated:] + 56
6 Isi For You 0x000a14b7 -[DetailViewController breadcrumbItemPressedAtIndex:] + 327
7 Isi For You 0x000c4460 -[ListHeaderViewController breadcrumbView:didTapItemAtIndex:] + 144
8 Isi For You 0x00094772 -[BTBreadcrumbView didTapItemAtIndex:] + 162
9 Isi For You 0x0009480f -[BTBreadcrumbView tapItemButton:] + 143
10 libobjc.A.dylib 0x02e33880 -[NSObject performSelector:withObject:withObject:] + 77
11 UIKit 0x018fe3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
12 UIKit 0x018fe345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
13 UIKit 0x019ffbd1 -[UIControl sendAction:to:forEvent:] + 66
14 UIKit 0x019fffc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
15 UIKit 0x019ff243 -[UIControl touchesEnded:withEvent:] + 641
16 UIKit 0x0193dddd -[UIWindow _sendTouchesForEvent:] + 852
17 UIKit 0x0193e9d1 -[UIWindow sendEvent:] + 1117
18 UIKit 0x019105f2 -[UIApplication sendEvent:] + 242
19 Isi For You 0x00434244 -[CustomUIApplication sendEvent:] + 100
20 UIKit 0x018fa353 _UIApplicationHandleEventQueue + 11455
21 CoreFoundation 0x0303177f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
22 CoreFoundation 0x0303110b __CFRunLoopDoSources0 + 235
23 CoreFoundation 0x0304e1ae __CFRunLoopRun + 910
24 CoreFoundation 0x0304d9d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x0304d7eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x042cc5ee GSEventRunModal + 192
27 GraphicsServices 0x042cc42b GSEventRun + 104
28 UIKit 0x018fcf9b UIApplicationMain + 1225
29 Isi For You 0x000449e2 main + 82
30 libdyld.dylib 0x038796d9 start + 1
)
That error usually occurs when the View Controller you are trying to pop to is not in the navigation stack. Although in your case it would seem that you view controller is in fact there... You can use popToRootViewControllerAnimated: to pop to your "root".
[self.navigationController popToRootViewControllerAnimated:YES];
If you try to pop without animation it will work. I faced this issue when tried to pop multiple view controllers animated.
If you want to pop n viewControllers till n-1 pop without animation, then pop the last one with animation.
You can use the
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
API on UINavigationController to hop between multiple stack position jumps or indeed completely replace the stack.
from the docs
The view controllers to place in the stack. The front-to-back order of
the controllers in this array represents the new bottom-to-top order
of the controllers in the navigation stack. Thus, the last item added
to the array becomes the top item of the navigation stack.
so recover your current stack with the viewControllers property , mutate as desired (in your case you would be taking a sub-array of the original stack) then dump it back onto the navigation controller.

Firing segues failing

I have a storyboard.
In this storyboard there is a UITableViewController that uses a custom class, comMasterViewController.
Using the storyboard, I simply control-drag from the UITableViewController to another scene.
A modal segue is created. I change its identifier to "loadingDataSegue".
In my UITableViewController code, I fire this line:
[self performSegueWithIdentifier:#"loadingDataSegue" sender:nil];
I receive:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<comMasterViewController: 0x1b6290>) has no segue with
identifier 'loadingDataSegue''
What isn't being hooked up properly?
Thanks for the help
EDIT:
I am pretty sure I am linking the TVC, and not any of the subviews. Looking at the storyboard code, I see the following:
<tableViewController storyboardIdentifier="comMasterViewController"
title="comMasterViewController" clearsSelectionOnViewWillAppear="NO" id="19"
userLabel="comMasterViewController" customClass="comMasterViewController"
sceneMemberID="viewController">
and at the bottom, as a child tag to <tableViewController> and not to any of its subviews:
<connections>
<segue destination="UCh-sM-lba" kind="modal" identifier="loadingDataSegue"
id="epP-jH-GLZ"/>
</connections>
Here is the stacktrace:
0 CoreFoundation
0x363388a7 __exceptionPreprocess + 186
1 libobjc.A.dylib
0x3758d259 objc_exception_throw + 32
2 UIKit
0x31193a3f -[UIViewController performSegueWithIdentifier:sender:] + 154
3 EZSystem
0x000bdfe7 -[comMasterViewController insertNewObject:] + 58
4 CoreFoundation
0x362923fd -[NSObject performSelector:withObject:withObject:] + 52
5 UIKit
0x30fc8faf -[UIApplication sendAction:to:from:forEvent:] + 62
6 UIKit
0x3108e76b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 118
7 CoreFoundation
0x362923fd -[NSObject performSelector:withObject:withObject:] + 52
8 UIKit
0x30fc8faf -[UIApplication sendAction:to:from:forEvent:] + 62
9 UIKit
0x30fc8f6b -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
10 UIKit
0x30fc8f49 -[UIControl sendAction:to:forEvent:] + 44
11 UIKit
0x30fc8cb9 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 492
12 UIKit
0x30fc95f1 -[UIControl touchesEnded:withEvent:] + 476
13 UIKit
0x30fc7ad3 -[UIWindow _sendTouchesForEvent:] + 318
14 UIKit
0x30fc74c1 -[UIWindow sendEvent:] + 380
15 UIKit
0x30fad83d -[UIApplication sendEvent:] + 356
16 UIKit
0x30fad0e3 _UIApplicationHandleEvent + 5826
17 GraphicsServices
0x3264f22b PurpleEventCallback + 882
18 CoreFoundation
0x3630c523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
19 CoreFoundation
0x3630c4c5 __CFRunLoopDoSource1 + 140
20 CoreFoundation
0x3630b313 __CFRunLoopRun + 1370
21 CoreFoundation
0x3628e4a5 CFRunLoopRunSpecific + 300
22 CoreFoundation
0x3628e36d CFRunLoopRunInMode + 104
23 GraphicsServices
0x3264e439 GSEventRunModal + 136
24 UIKit
0x30fdbe7d UIApplicationMain + 1080
25 EZSystem
0x0009f963 main + 86
26 EZSystem
0x0009f908 start + 40
Here is an image:
Make sure you didn't drag that Segue from a TableView Row or UIButton and instead from the VC itself. If you are in doubt, delete the segue and connect it again. Also check for typo's (including case) if that doesn't solve your issue.
I had this exact problem(the symptoms anyway) and ElJay gave me the hint I needed. My problem was caused by the TableViewController being inside a NavigationController and it was opened by an alloc init and push using the NavigationController. This was the reason [self performSegueWithIdentifier] didn't work. Even more, this was also the reason the segue I created from the cell didn't work, so now I don't even need the [self perform...] part, just prepareForSegue and everything works like a charm.
I would have replied this to ElJay, but for some reason I can't. All I could do was give him a vote.

How to determine which NSNotification is crashing due to dealloc-ed observer

The golden rule of using NSNotification seems to be
"call removeObserver before the observer (or the object) is deallocated".
I'm dealing with a codebase where this rule hasn't been followed, but I can't locate the transgression. I've searched through the code and ensured that every addObserver has a matching removeObserver but I'm still seeing crash reports of the following variety:
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x8
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x31516fbc objc_msgSend + 16
1 Foundation 0x3195b50f __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 19
2 CoreFoundation 0x37a02577 ___CFXNotificationPost_block_invoke_0 + 71
3 CoreFoundation 0x3798e0cf _CFXNotificationPost + 1407
4 Foundation 0x318cf3fb -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
5 UIKit 0x34e5ee25 -[UIApplication _handleApplicationSuspend:eventInfo:] + 697
6 UIKit 0x34deed17 -[UIApplication handleEvent:withNewEvent:] + 2031
7 UIKit 0x34dee3bf -[UIApplication sendEvent:] + 55
8 UIKit 0x34dedd2d _UIApplicationHandleEvent + 5809
9 GraphicsServices 0x3750bdf3 PurpleEventCallback + 883
10 CoreFoundation 0x37a0a553 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 39
11 CoreFoundation 0x37a0a4f5 __CFRunLoopDoSource1 + 141
12 CoreFoundation 0x37a09343 __CFRunLoopRun + 1371
13 CoreFoundation 0x3798c4dd CFRunLoopRunSpecific + 301
14 CoreFoundation 0x3798c3a5 CFRunLoopRunInMode + 105
15 GraphicsServices 0x3750afcd GSEventRunModal + 157
16 UIKit 0x34e1c743 UIApplicationMain + 1091
17 App 0x00002d2f main (main.m:14)
My interpretation of this crash report is that [UIApplication _handleApplicationSuspend:eventInfo:] is posting a notification for which an observer has been deallocated before being removed.
Assuming this interpretations is correct, how would I go about determining which notification is being posted? And ideally, what the deallocated object type?
You can set a symbolic breakpoint in -[NSNotificationCenter postNotificationName:object:userInfo:] and print the third argument passed to it (the first being the NSNotificationCenter, the second, _cmd) using the debugger po command.
Another way to determine this is to get the name parameter value (the string you passed for posting the notification) and verify that any object that is observing that string/name is set to remove observation sometime in the objects lifecycle or as it is deallocating.

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.