Using ARC (Automatic Reference Counting), I have a UIButton in a subclassed UITableViewCell. The table view controller implements the IBAction which is hooked up to the UIButton. In the subclassed cell's xib, the same table view controller is the File's Owner.
The problem occurs when I run the app and click on the button, I get an EXC_BAD_ACCESS. It's clearly visible on the iPhone screen, so it is being allocated at some point.
Any idea what the problem could be? Thanks in advance!
EDIT1:
Note: I have env variable NSZombieEnabled set to true.
Here's the console:
2011-10-31 22:22:08.653 MyApp[7176:fb03] *** -[NSObject performSelector:withObject:withObject:]: message sent to deallocated instance 0x6b94d40
(lldb) thread backtrace
* thread #1: tid = 0x1f03, 0x014c3e1e CoreFoundation`___forwarding___ + 206, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x014c3e1e CoreFoundation`___forwarding___ + 206
frame #1: 0x014c3ce2 CoreFoundation`_CF_forwarding_prep_0 + 50
frame #2: 0x001e45c2 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #3: 0x001e455a UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
frame #4: 0x00289b76 UIKit`-[UIControl sendAction:to:forEvent:] + 66
frame #5: 0x0028a03f UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
frame #6: 0x002892fe UIKit`-[UIControl touchesEnded:withEvent:] + 549
frame #7: 0x004a2a2a UIKit`_UIGestureRecognizerUpdate + 6725
frame #8: 0x015319ce CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #9: 0x014c8670 CoreFoundation`__CFRunLoopDoObservers + 384
frame #10: 0x014944f6 CoreFoundation`__CFRunLoopRun + 1174
frame #11: 0x01493db4 CoreFoundation`CFRunLoopRunSpecific + 212
frame #12: 0x01493ccb CoreFoundation`CFRunLoopRunInMode + 123
frame #13: 0x02449879 GraphicsServices`GSEventRunModal + 207
frame #14: 0x0244993e GraphicsServices`GSEventRun + 114
frame #15: 0x001e1a9b UIKit`UIApplicationMain + 1175
frame #16: 0x0000278d MyApp`main + 125 at main.m:14
frame #17: 0x00001ff5 MyApp`start + 53
Figured it out. I was using UINib's instantiateWithOwner: options: to load the nib of the custom UITableViewCell. I was setting the owner to nil. Setting the owner to my view controller fixed it. Also, my view controller is the File's Owner of that UITableViewCell nib. I'm guessing because the view controller and nib were not properly linked, ARC did not see a reason to keep the view around.
I am not sure but I have a feeling your problem is in the selector you are passing to the button.
Try to see if you are using a selector with ":" to a method with out parameters.
If you are using selector that looks like this:
#selector(method:)
Then is is expected that "method" will take parameters:
-(IBAction)method:(UIButton)sender{
}
if your function is not taking any parameters:
-(IBAction)method{
}
then your selector should look like that:
#selector(method)
Related
I am getting this crash after converting an existing UIViewController to Auto Layout and I can't figure out what is causing it. I did search for dispatch_async(dispatch_get_global_queue(...)) calls but none changes layout.
The stack trace is also very unhelpful:
* thread #18: tid = 0x73617, 0x0000000183aa8524 libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 3.1
* frame #0: 0x0000000183aa8524 libobjc.A.dylib`objc_exception_throw
frame #1: 0x0000000185071100 CoreFoundation`+[NSException raise:format:] + 116
frame #2: 0x0000000185c83894 Foundation`_AssertAutolayoutOnAllowedThreadsOnly + 192
frame #3: 0x0000000185c835d4 Foundation`-[NSISEngine _optimizeWithoutRebuilding] + 76
frame #4: 0x0000000185aceddc Foundation`-[NSISEngine optimize] + 112
frame #5: 0x0000000185c82270 Foundation`-[NSISEngine performPendingChangeNotifications] + 112
frame #6: 0x000000018af23e18 UIKit`-[UIView(Hierarchy) layoutSubviews] + 220
frame #7: 0x000000018b15fff8 UIKit`-[UISlider layoutSubviews] + 192
frame #8: 0x000000018af23a80 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1196
frame #9: 0x00000001883d19d8 QuartzCore`-[CALayer layoutSublayers] + 148
frame #10: 0x00000001883c64cc QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 292
frame #11: 0x00000001883c638c QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
frame #12: 0x00000001883433e0 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 252
frame #13: 0x000000018836aa68 QuartzCore`CA::Transaction::commit() + 512
frame #14: 0x000000018836af34 QuartzCore`CA::Transaction::release_thread(void*) + 660
frame #15: 0x0000000184103fbc libsystem_pthread.dylib`_pthread_tsd_cleanup + 572
frame #16: 0x0000000184103ce4 libsystem_pthread.dylib`_pthread_exit + 200
frame #17: 0x0000000184103378 libsystem_pthread.dylib`_pthread_wqthread + 1504
frame #18: 0x0000000184102d8c libsystem_pthread.dylib`start_wqthread + 4
(lldb)
Is there any way to figure out the exact place that triggered the layout?
Always for change at UI should be work on main thread. also an important subject is you can make an object from view at background thread!!! but for show in view or another changes on it just should be work on main thread, and this subject is main reason for occurrences this problem.
finally for solve this problem you can easily use from 'DispatchQueue'
DispatchQueue.main.async {
// do your work
}
I finally found out the problem after taking another look at the stack trace. The problem was that I was changing the value property of a UISlider instance on a background thread.
But nowhere does it state that you have to change it on the main thread! (Thanks, Apple) Apparently, it seems like UISlider implements the value's setter and forces a layout or something similar.
I am getting a EXC_BAD_ACCESS error every time I trigger a certain segue in my app. Thanks to these two links, I learned you can trouble shoot EXC_BAD_ACCESS easier after enabling NSZombies.
How do I set up NSZombieEnabled in Xcode 4?
http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/
I am using this app adhoc and testing it adhoc. http://www.raywenderlich.com/13511/how-to-create-an-app-like-instagram-with-a-web-service-backend-part-12
When the app loads, a UIScrollView with pictures are shown. When you tap a picture, a push segue is triggered to the fullscreen shot of that picture. The app runs perfectly on iPad but on my iPhone 4 it crashes every time before the push segue. Ive been stuck on this for a week. I just found out what NSZombies are and how to enable them: after I enable them the dubber reads as follows:
2015-07-03 22:26:36.170 iReporter[1878:60b] *** -[CFNumber retain]: message sent to deallocated instance 0x172e6210
After learning how to input 'bt' into the debugger out put to get more info, this is what the debugger reads now;
* thread #1: tid = 0x7246e, 0x2f1e515c CoreFoundation`___forwarding___ + 540, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xdefe)
* frame #0: 0x2f1e515c CoreFoundation`___forwarding___ + 540
frame #1: 0x2f134768 CoreFoundation`_CF_forwarding_prep_0 + 24
frame #2: 0x2f11e5a8 CoreFoundation`+[__NSDictionaryM __new:::::] + 536
frame #3: 0x2f1212f0 CoreFoundation`-[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 240
frame #4: 0x2f125dcc CoreFoundation`+[NSDictionary dictionaryWithObjectsAndKeys:] + 372
frame #5: 0x000c96a4 iReporter`-[StreamPhotoScreen viewDidLoad](self=0x172e7560, _cmd=0x32053af3) + 256 at StreamPhotoScreen.m:20
frame #6: 0x31a044aa UIKit`-[UIViewController loadViewIfRequired] + 518
frame #7: 0x31a04268 UIKit`-[UIViewController view] + 24
frame #8: 0x31b9036a UIKit`-[UINavigationController _startCustomTransition:] + 634
frame #9: 0x31aadd62 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 418
frame #10: 0x31aadb6c UIKit`-[UINavigationController __viewWillLayoutSubviews] + 44
frame #11: 0x31aadb04 UIKit`-[UILayoutContainerView layoutSubviews] + 184
frame #12: 0x319ffd58 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 380
frame #13: 0x3167d62a QuartzCore`-[CALayer layoutSublayers] + 142
frame #14: 0x31678e3a QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 350
frame #15: 0x31678ccc QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
frame #16: 0x316786de QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 230
frame #17: 0x316784ee QuartzCore`CA::Transaction::commit() + 314
frame #18: 0x31a033e0 UIKit`_UIApplicationHandleEventQueue + 8232
frame #19: 0x2f1ae20a CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
frame #20: 0x2f1ad6da CoreFoundation`__CFRunLoopDoSources0 + 206
frame #21: 0x2f1abece CoreFoundation`__CFRunLoopRun + 622
frame #22: 0x2f116ebe CoreFoundation`CFRunLoopRunSpecific + 522
frame #23: 0x2f116ca2 CoreFoundation`CFRunLoopRunInMode + 106
frame #24: 0x3401c662 GraphicsServices`GSEventRunModal + 138
frame #25: 0x31a6314c UIKit`UIApplicationMain + 1136
frame #26: 0x000c699c iReporter`main(argc=1, argv=0x27d44cec) + 108 at main.m:16
(lldb)
If i need to post more code/info it might be this: (section of code that the editor highlights on crash sometimes as well telling me its EXC_BAD_ACCESS_)
[api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:#"stream", #"command", IdPhoto,#"IdPhoto", nil] onCompletion:^(NSDictionary *json) {
All I am trying to do is call the above data using j son and load it via a push segue. It works absolutely fine on iPad but crashes every time on iPhone 4?
Find the NSNumber property declaration,and check if you have wrongly give a type of assign.
I have a UIViewController with UITextView in the storyboard I assigned it with strong variable.The first time when I present the ViewController using story board segue there is no crash but when I dismiss the ViewController and again present the ViewController for the second time after [UITextView becomeFirstResponder] is called the app crashes and shows the following error
[UIViewController _responderWindow]: message sent to deallocated instance
I have assigned delegate to the ViewController in which the TextView is added and implemented all the delegate methods
I tried calling this method [UITextview becomeFirstResponder] after a delay
but no use it was still crashing
I tried profiling with zombie template the error is in UIKit
this is the response I am getting when the app crashed if enable zombies in the product scheme
[ReviewViewController _responderWindow]: message sent to deallocated instance 0x14ed3a2a0
this is the code I am using to present the viewcontroller which has the textview
[_promotionsViewControllerDelegate performSegueWithIdentifier:#"testing" sender:nil];
textview viewcontroller
- (void)viewDidLoad {
[super viewDidLoad];
_reviewTextView.delegate = self;
[_reviewTextView becomeFirstResponder];
}
this is the back trace error log when i run the application without zombies
* thread #1: tid = 0x758d4, 0x000000019271bbd0 libobjc.A.dylib`objc_msgSend + 16, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x174697260)
frame #0: 0x000000019271bbd0 libobjc.A.dylib`objc_msgSend + 16
frame #1: 0x000000018675f96c UIKit`-[UIView(Internal) _firstResponder] + 24
frame #2: 0x000000018675f940 UIKit`-[UIResponder isFirstResponder] + 32
frame #3: 0x0000000186e96ed8 UIKit`-[UITextView _keyboardDidShow:] + 32
frame #4: 0x0000000181f58ae4 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
frame #5: 0x0000000181e97220 CoreFoundation`_CFXNotificationPost + 2060
frame #6: 0x0000000182d96cc0 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 72
frame #7: 0x0000000186e5f458 UIKit`-[UIInputWindowController postEndNotifications:withInfo:] + 580
frame #8: 0x0000000186e60c7c UIKit`__77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke595 + 396
frame #9: 0x000000018679c0a4 UIKit`-[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 408
frame #10: 0x000000018679bc0c UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 188
frame #11: 0x000000018679bb14 UIKit`-[UIViewAnimationState animationDidStop:finished:] + 104
frame #12: 0x00000001860c0f64 QuartzCore`CA::Layer::run_animation_callbacks(void*) + 296
frame #13: 0x00000001002b4df0 libdispatch.dylib`_dispatch_client_callout + 16
frame #14: 0x00000001002b975c libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1056
frame #15: 0x0000000181f69fa4 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
frame #16: 0x0000000181f6804c CoreFoundation`__CFRunLoopRun + 1492
frame #17: 0x0000000181e950a4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #18: 0x000000018b0375a4 GraphicsServices`GSEventRunModal + 168
frame #19: 0x00000001867ca3c0 UIKit`UIApplicationMain + 1488
* frame #20: 0x00000001000c1030 WineDisciples`main(argc=1, argv=0x000000016fd83a58) + 116 at main.m:14
frame #21: 0x0000000192d76a08 libdyld.dylib`start + 4
I Kindly request you to help me on this thanks..
Did you check your Identifier in inspector window similar to given in code (i.e. "testing" )?
Also in your .h file had you given the . If not then add it.
Maybe is too late, but I had the same problem and the solution was to send remove from superview in the dealloc method of my vwc
deinit {
self.commentTextView.delegate = nil
self.commentTextView.removeFromSuperview()
}
I've tried seating SO and Google but it seems no one has had this issue.
I have two ViewControllers in my iOS app.
In viewControllerA on a tap event I call:
[self performSegueWithIdentifier:#"fooSegue" sender:self];
Which this calls:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
on viewControllerA
No problem there.
However after that method,
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
is called on viewControllerB before viewDidLoad is even called. I don't need this mothod to run on this viewController at this stage. Along with that, viewDidLoad / viewWillApear are called twice after the prepareForSegue has been called on viewControllerB
I tried doing a stack strace to see who is calling it - but this is what I got:
* thread #1: tid = 0x5eac3, 0x0001e859 TestApp`-[viewControllerB prepareForSegue:sender:](self=0x0dad98b0, _cmd=0x0188185a, segue=0x0ce9e6f0, sender=0x0dad98b0) + 89 at viewControllerB.m:444, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1 * frame #0: 0x0001e859 TestApp`-[ViewControllerB prepareForSegue:sender:](self=0x0dad98b0, _cmd=0x0188185a, segue=0x0ce9e6f0, sender=0x0dad98b0) + 89 at ViewControllerB.m:444
frame #1: 0x015f8efa UIKit`-[UIStoryboardSegueTemplate _perform:] + 156
frame #2: 0x015f8f87 UIKit`-[UIStoryboardSegueTemplate perform:] + 115
frame #3: 0x011b32e2 UIKit`-[UIViewController loadViewIfRequired] + 605
frame #4: 0x011b35d9 UIKit`-[UIViewController view] + 35
frame #5: 0x011cd942 UIKit`-[UINavigationController _startCustomTransition:] + 778
frame #6: 0x011da8f7 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 688
frame #7: 0x011db4e9 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 57
frame #8: 0x0131c0d1 UIKit`-[UILayoutContainerView layoutSubviews] + 213
frame #9: 0x01103964 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
frame #10: 0x023e682b libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #11: 0x0286245a QuartzCore`-[CALayer layoutSublayers] + 148
frame #12: 0x02856244 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380
frame #13: 0x028560b0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
frame #14: 0x027bc7fa QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
frame #15: 0x027bdb85 QuartzCore`CA::Transaction::commit() + 393
frame #16: 0x0287b5b0 QuartzCore`+[CATransaction flush] + 52
frame #17: 0x010929bb UIKit`_UIApplicationHandleEventQueue + 13095
frame #18: 0x02a1e77f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
+ 15
frame #19: 0x02a1e10b CoreFoundation`__CFRunLoopDoSources0 + 235
frame #20: 0x02a3b1ae CoreFoundation`__CFRunLoopRun + 910
frame #21: 0x02a3a9d3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #22: 0x02a3a7eb CoreFoundation`CFRunLoopRunInMode + 123
frame #23: 0x04bca5ee GraphicsServices`GSEventRunModal + 192
frame #24: 0x04bca42b GraphicsServices`GSEventRun + 104
frame #25: 0x01094f9b UIKit`UIApplicationMain + 1225
frame #26: 0x0011112d TestApp`main(argc=1, argv=0xbfffedf8) + 141 at main.m:16
I'm not sure what to make of this.
Can anyone asset with whats going on here?
If the destination scene has a "container view" that you added via Interface Builder, that includes an embed segue, which is automatically called when you transition to the parent view controller. This segue will trigger the instantiation of the child view controller and its view(s) and this process ends up calling prepareForSegue on the parent view controller, giving it a chance to pass whatever information the child view controller might need (if anything).
You should see viewDidLoad, viewDidAppear, etc., to be called on the destination's parent view controller, as well as on the child view controller.
I am experiencing a very strange crash, here is the backtrace.
* thread #1: tid = 0x2403, 0x3379516c CoreFoundation`CFHash + 8, stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xdefe)
frame #0: 0x3379516c CoreFoundation`CFHash + 8
frame #1: 0x33797a9c CoreFoundation`CFBasicHashRemoveValue + 1408
frame #2: 0x337974ee CoreFoundation`CFDictionaryRemoveValue + 166
frame #3: 0x3420988e Foundation`-[NSISEngine removeConstraintWithMarker:] + 562
frame #4: 0x34211dbe Foundation`-[NSLayoutConstraint _removeFromEngine:] + 230
frame #5: 0x35a954ec UIKit`-[UIView(UIConstraintBasedLayout) _layoutEngine_willRemoveLayoutConstraint:] + 44
frame #6: 0x358488fc UIKit`__48-[UIScrollView _setAutomaticContentConstraints:]_block_invoke_0 + 148
frame #7: 0x34208882 Foundation`-[NSISEngine withAutomaticOptimizationDisabled:] + 166
frame #8: 0x35848838 UIKit`-[UIScrollView _setAutomaticContentConstraints:] + 116
frame #9: 0x35848e6c UIKit`-[UIScrollView _rememberDependentConstraint:] + 112
frame #10: 0x35a9e3ae UIKit`___updateViewDependenciesForConstraint_block_invoke_0 + 30
frame #11: 0x35a954ba UIKit`_updateViewDependenciesForConstraint + 202
frame #12: 0x35a953da UIKit`-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 154
frame #13: 0x35a95534 UIKit`-[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 36
frame #14: 0x3567c2e0 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 376
frame #15: 0x356d34fe UIKit`-[UIScrollView _didMoveFromWindow:toWindow:] + 50
frame #16: 0x3567c5c6 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 1118
frame #17: 0x35676e52 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 138
frame #18: 0x3565e7dc UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1300
frame #19: 0x3565e2c2 UIKit`-[UIView(Hierarchy) addSubview:] + 30
frame #20: 0x356f68e8 UIKit`-[UITransitionView transition:fromView:toView:removeFromView:] + 972
frame #21: 0x35937618 UIKit`__91-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]_block_invoke_0238 + 388
frame #22: 0x357499b8 UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 4824
frame #23: 0x357b9814 UIKit`-[UIViewController _dismissViewControllerWithTransition:from:completion:] + 1708
frame #24: 0x357057c4 UIKit`-[UIViewController dismissViewControllerWithTransition:completion:] + 912
frame #25: 0x000ccd40 Capture`-[INFTagSearchViewController cancelButtonTouched:](self=0x1f09ed50, _cmd=0x001b9d5f, sender=0x1e0265c0) + 76 at INFTagSearchViewController.m:48
frame #26: 0x357470c4 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 72
frame #27: 0x35747076 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
frame #28: 0x35747054 UIKit`-[UIControl sendAction:to:forEvent:] + 44
frame #29: 0x3574690a UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 502
frame #30: 0x35746e00 UIKit`-[UIControl touchesEnded:withEvent:] + 488
frame #31: 0x3566f5f0 UIKit`-[UIWindow _sendTouchesForEvent:] + 524
frame #32: 0x3565c800 UIKit`-[UIApplication sendEvent:] + 380
frame #33: 0x3565c11a UIKit`_UIApplicationHandleEvent + 6154
frame #34: 0x373655a2 GraphicsServices`_PurpleEventCallback + 590
frame #35: 0x373651d2 GraphicsServices`PurpleEventCallback + 34
frame #36: 0x33829172 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #37: 0x33829116 CoreFoundation`__CFRunLoopDoSource1 + 138
frame #38: 0x33827f98 CoreFoundation`__CFRunLoopRun + 1384
frame #39: 0x3379aebc CoreFoundation`CFRunLoopRunSpecific + 356
frame #40: 0x3379ad48 CoreFoundation`CFRunLoopRunInMode + 104
frame #41: 0x373642ea GraphicsServices`GSEventRunModal + 74
frame #42: 0x356b0300 UIKit`UIApplicationMain + 1120
frame #43: 0x000a297c Capture`main(argc=1, argv=0x2fd60cfc) + 116 at main.m:16
frame #44: 0x3bb2bb20 libdyld.dylib`start + 4
You will notice frame 25 is the only call my code makes, and it is cancelButtonTouched which looks like.
- (IBAction)cancelButtonTouched:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
I am at a loss as to what is going on, I've never had an issue like this before, based on the system calls it appears to be an auto-layout issue. I verified that viewWillApper is called on the presenting view controller before the crash occurs, so I assume it is an issuing during layout of the presenting view.
Any ideas on how to narrow this issue down to a specific layout contstraint? Or any other ideas?
This is reproduceable on some devices, where as on others it rarely if ever happens. So it is intermittent.
Update
Screenshot of breakpoint.
Update 2
So it is definitely an issue with dismissing to the presentingViewController, dismissing two levels deep ([self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]) works fine, but obviously not the desired result, I only want to go back 1 level. This further leads me to believe there is an issue "re-laying" out the view.
I seem to remember something like this, though not sure it was the exact same thing. In my case, it was caused by calling addSubview: (or insertSubview:...) with a view which already was a subview. While normally I think UIView deals with that, with auto layout it seems that it's possible for some associated information to be added elsewhere twice, and there can be a crash when trying to clean out that associated information. In my case, the solution was to ensure that I only added subviews once, and this crash (or my similar one anyways) went away.
Based on idea of Carl Lindberg I prepared and used the following iOS category and I have no crash anymore:
UIView+AddSubviewWithRemovingFromParent.h
#import <UIKit/UIKit.h>
#interface UIView (AddSubviewWithRemovingFromParent)
- (void)addSubviewWithRemovingFromParent:(UIView *)view;
#end
UIView+AddSubviewWithRemovingFromParent.m
#import "UIView+AddSubviewWithRemovingFromParent.h"
#implementation UIView (AddSubviewWithRemovingFromParent)
- (void)addSubviewWithRemovingFromParent:(UIView *)view {
if (view.superview != nil) {
[view removeFromSuperview];
}
[self addSubview:view];
}
#end
now you can use the addSubviewWithRemovingFromParent method to add the subView instead of addSubview method like this:
UITableViewCell *cell = [[UITableViewCell alloc] init];
[cell.contentView addSubviewWithRemovingFromParent:<viewToAdd>];
To sum it up:
find all references of addSubView in your controllers where the app
is crashing
import the category UIView+AddSubviewWithRemovingFromParent.h
use method addSubviewWithRemovingFromParent instead of addSubView
In my case this crash happened when I had a view controller in a storyboard but loaded the view contents in from a NIB with the same view controller as the file owner. This normally works fine, but I had the view outlet set in both the storyboard and the NIB, which triggered the iOS6 "add subview twice" bug. By clearing the view outlet in the NIB all was fixed.
I had / have the same problem.
The same problem occurs to me, when i present two view controllers modally above each other and want to return to the first one.
Disabling autolayout for the first presented view only solves the issue for me.
In your case self.presentingviewcontroller
Unfortunately i wasn't able to narrow it down further.