UITextView becomeFirstResponder crash with EXC bad access - ios

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()
}

Related

iOS app crashes on an iPhone even though it runs on simulator

Even though it worked nicely on the simulator, my multiview app crashes on an iPhone 5 C (by ’nicely’, I mean no memory leaks, smooth animation as buttons move into place, etc.). The app is written in Objective C, The simulator runs under Xcode 8.3.3. The phone runs iOS 10.3.3.
The problem happens when I press a sync button that switches from SyncViewController to PlayViewController i.e. from VC3 to VC4 after switching successfully from VC1 to VC2 to VC3. Each ViewController has a delegate method that responds to buttons pressed from within the previous ViewController.
The crash happens consistently in the following method that displays three things in PlayView : a horizontally scrollable graphic score, a button with a time display that is overwritten every second and a stop button.
- (UIView *)showScoreClockAndExit:(CGRect)panel highlight:(int)currentState seconds:(NSUInteger)clockCount {
if (!self.seconds)
{
[self.seconds removeFromSuperview];
self.seconds = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
[self addSubview:_seconds];
}
ClockButton *seconds = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
[self addSubview:seconds];
EscButton *escape = [[EscButton alloc] loadEscButton:(NSString *)#"stop"];
[self addSubview:escape];
GraphicScore *score = [[GraphicScore alloc] createGraphicScore:(CGRect)panel highlight:(int)currentState];
[self addSubview:score];
return self;
}
What is weird is that the last UIView previously loaded by SyncViewController remains frozen on the device itself even though the PlayViewController has already begun taking over from SyncViewController, i.e PlayView is loaded, a UITimer is set up and the state of play for the selected player is enabled, as the debug log (below) clearly shows
2017-07-24 15:25:24.950097+1000 SatGam2[3052:1712261] PlayView loaded (selectedFamily:1 selectedPlayerID:1)
2017-07-24 15:25:24.950923+1000 SatGam2[3052:1712261] TIME: 00:00
2017-07-24 15:25:24.951905+1000 SatGam2[3052:1712261] ENABLED (player 1: state 0)
(lldb)
Following a helpful lead I found here, I typed : bt and pressed: Enter to get the following log
SatGam2 was compiled with optimization - stepping may behave oddly; variables may not be available.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xe15d25d2)
frame #0: 0x1b300694 libobjc.A.dylib`objc_retain + 4
frame #1: 0x21291d0a UIKit`-[UIView(Hierarchy) addSubview:] + 18
* frame #2: 0x000c2696 SatGam2`-[PlayView showScoreClockAndExit:highlight:seconds:](self=0x15e9ed70, _cmd=<unavailable>, panel=<unavailable>, currentState=<unavailable>, clockCount=<unavailable>) at PlayView.m:215 [opt]
frame #3: 0x000c246c SatGam2`-[PlayView initWithFrame:state:family:player:cue:seconds:](self=<unavailable>, _cmd=<unavailable>, frame=<unavailable>, currentState=<unavailable>, selectedFamily=<unavailable>, selectedPlayerID=<unavailable>, entryString=#"", clockCount=<unavailable>) at PlayView.m:149 [opt]
frame #4: 0x000cd0da SatGam2`-[PlayViewController nextState](self=0x168aae00, _cmd=<unavailable>) at PlayViewController.m:244 [opt]
frame #5: 0x000ccc40 SatGam2`-[PlayViewController viewDidLoad](self=0x168aae00, _cmd=<unavailable>) at PlayViewController.m:152 [opt]
frame #6: 0x2128b27e UIKit`-[UIViewController loadViewIfRequired] + 966
frame #7: 0x2128aea0 UIKit`-[UIViewController view] + 22
frame #8: 0x000c1266 SatGam2`-[MultiviewViewController displayView:](self=0x15d85710, _cmd=<unavailable>, intNewView=4) at MultiviewViewController.m:45 [opt]
frame #9: 0x000c2fb6 SatGam2`-[SyncViewController fromSyncButton:](self=<unavailable>, _cmd=<unavailable>, button=<unavailable>) at SyncViewController.m:65 [opt]
frame #10: 0x212bf784 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 76
frame #11: 0x212bf718 UIKit`-[UIControl sendAction:to:forEvent:] + 62
frame #12: 0x212a9d48 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 478
frame #13: 0x212bf054 UIKit`-[UIControl touchesEnded:withEvent:] + 604
frame #14: 0x212beb9e UIKit`-[UIWindow _sendTouchesForEvent:] + 2094
frame #15: 0x212b9ade UIKit`-[UIWindow sendEvent:] + 2798
frame #16: 0x2128b682 UIKit`-[UIApplication sendEvent:] + 308
frame #17: 0x21a1ede6 UIKit`__dispatchPreprocessedEventFromEventQueue + 2254
frame #18: 0x21a1978a UIKit`__handleEventQueue + 4186
frame #19: 0x21a19b6c UIKit`__handleHIDEventFetcherDrain + 144
frame #20: 0x1c01bfdc CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
frame #21: 0x1c01bb04 CoreFoundation`__CFRunLoopDoSources0 + 424
frame #22: 0x1c019f50 CoreFoundation`__CFRunLoopRun + 1160
frame #23: 0x1bf6d1ae CoreFoundation`CFRunLoopRunSpecific + 470
frame #24: 0x1bf6cfd0 CoreFoundation`CFRunLoopRunInMode + 104
frame #25: 0x1d717b40 GraphicsServices`GSEventRunModal + 80
frame #26: 0x212eee12 UIKit`UIApplicationMain + 150
frame #27: 0x1b75a4ea libdyld.dylib`start + 2
(lldb)
I cleared all apps previously tested on the phone. I also tried a version of the app backed up last month to eliminate any problems I may have introduced since I began working on deviceMotion. But the problem remains the same.
Has anyone seen something like this ? Where would I begin ? e.g. like where would I put a breakpoint ?
This checking is incorrect.
if (!self.seconds)
{
[self.seconds removeFromSuperview];
self.seconds = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
[self addSubview:_seconds];
}
!self.seconds could be used if it is a boolean. In this case it seems self.seconds is some sort of a view. So what you should do is:
if (self.seconds!=nil) {
[self.seconds removeFromSuperView];
self.seconds = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
[self addSubview:_seconds];
}

[CFNumber retain]: message sent to deallocated instance

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.

iOS 6 EXC_BAD_ACCESS (code=2, address=0x15) When Presenting Game Center, But fine in iOS 7+

Trying to present my GKGameCenterViewController. It works fine in iOS 7, but when i try to.....
GKGameCenterViewController *gamecenterViewController = [[GKGameCenterViewController alloc]init];
gamecenterViewController.viewState = GKGameCenterViewControllerStateDefault;
gamecenterViewController.gameCenterDelegate = self;
[[CCDirector sharedDirector] presentModalViewController:gamecenterViewController animated:YES];
...in iOS 6, i get a iOS 6 EXC_BAD_ACCESS (code=2, address=0x15) error.
I've tried stepping in, but seems to step through ok until it gets to the funny looking code...
I've read many pre-existing and similar faults, but most seem to report additional output from the debugger, but I'm simply not getting anything more than the above quoted error...
This is my bt output after the crash took place..
(lldb) bt
*thread #1: tid = 0x697d9, 0x024a709b libobjc.A.dylib`objc_msgSend + 15, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=2, address=0x47)
frame #0: 0x024a709b libobjc.A.dylib`objc_msgSend + 15
frame #1: 0x0222fb4b GameKit`__55-[GKGameCenterViewController _setupChildViewController]_block_invoke_083 + 42
frame #2: 0x0222b896 GameKit`__61-[GKHostedViewController requestRemoteViewControllerIfNeeded]_block_invoke_0113 + 1167
frame #3: 0x00c9e48f UIKit`__block_global_11 + 154
frame #4: 0x026cd731 libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 89
frame #5: 0x026dc014 libdispatch.dylib`_dispatch_client_callout + 14
frame #6: 0x026cc7d5 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 296
frame #7: 0x038bdaf5 CoreFoundation`__CFRunLoopRun + 1925
frame #8: 0x038bcf44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #9: 0x038bce1b CoreFoundation`CFRunLoopRunInMode + 123
frame #10: 0x03c027e3 GraphicsServices`GSEventRunModal + 88
frame #11: 0x03c02668 GraphicsServices`GSEventRun + 104
frame #12: 0x007bfffc UIKit`UIApplicationMain + 1211 * frame #13: 0x0008c0d6 Monkey Puzzle`main(argc=1, argv=0xbffff040) + 134 at main.m:14 (lldb)
With Zombies turned on in the debug menu, the Backtrace looks slightly different
(lldb) bt
*thread #1: tid = 0x6fb94, 0x02b35286 libsystem_kernel.dylib`__kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGKILL
frame #0: 0x02b35286 libsystem_kernel.dylib`__kill + 10
frame #1: 0x02b335ec libsystem_kernel.dylib`kill$UNIX2003 + 32
frame #2: 0x03907aac CoreFoundation`___forwarding___ + 316
frame #3: 0x0390794e CoreFoundation`__forwarding_prep_0___ + 14
frame #4: 0x02230b4b GameKit`__55-[GKGameCenterViewController _setupChildViewController]_block_invoke_083 + 42
frame #5: 0x0222c896 GameKit`__61-[GKHostedViewController requestRemoteViewControllerIfNeeded]_block_invoke_0113 + 1167
frame #6: 0x00c9f48f UIKit`__block_global_11 + 154
frame #7: 0x026ce731 libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 89
frame #8: 0x026dd014 libdispatch.dylib`_dispatch_client_callout + 14
frame #9: 0x026cd7d5 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 296
frame #10: 0x038beaf5 CoreFoundation`__CFRunLoopRun + 1925
frame #11: 0x038bdf44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #12: 0x038bde1b CoreFoundation`CFRunLoopRunInMode + 123
frame #13: 0x03c037e3 GraphicsServices`GSEventRunModal + 88
frame #14: 0x03c03668 GraphicsServices`GSEventRun + 104
frame #15: 0x007c0ffc UIKit`UIApplicationMain + 1211 * frame #16: 0x0008cba6 Monkey Puzzle`main(argc=1, argv=0xbffff00c) + 134 at main.m:14 (lldb)
When doing a Product/Profile/Zombies run, I received this after pressing the button in my menu at the 40 second mark...
Any advice please?
OK fixed it....
I have a method in a custom class that handles weather or not to bring up all leaderboards or a specific one... here is one example of how i call it...
-(void)displayLeaderboard:(id)sender
{
[[ABGameKitHelper sharedHelper] showLeaderboard:#""];
}
If i pass an empty string to it, its meant to show just the gamcenter main screen, with all the leaderboards. If i send it any string, it will show the default leaderboard ("level 1"), and if i pass it a valid leaderboardID, it will show that leaderboard....
Used to look like this...
-(void) showLeaderboard:(NSString*)leaderboardId
{
GKGameCenterViewController *gamecenterViewController = [[GKGameCenterViewController alloc]init];
GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc]init];
if ([leaderboardId isEqualToString:#""])
{
gamecenterViewController.viewState = GKGameCenterViewControllerStateDefault;
gamecenterViewController.gameCenterDelegate = self;
[[self topViewController] presentViewController:gamecenterViewController animated:YES completion:nil];
}
else
{
leaderboardViewController.leaderboardDelegate = self;
leaderboardViewController.category = leaderboardId;
[[self topViewController] presentViewController:leaderboardViewController animated:YES completion:nil];
}
}
This worked FINE on iOS 7, however iOS 6 would crash with the information i provided in the above question.
It turns out that the solution was to include the definition inside the if statement. I have no idea why iOS 6 isn't happy with declaring both of them, and only using one... The only reason i noticed something was us was because i saw [GKLeaderboardViewController _endDelayingPresentation]: message sent to deallocated instance 0xaac8d20 in the debug, when (although similar) i was actually always only ever needing to call the GKGameCenterViewController... So moving the declarations to within the IF statement solved this issue that would have otherwise not allowed me to deploy to iOS 6...
I would really love to read some comments on this to help me understand obj-c a little better, thanks....

Strange Crash when dismissing view controller, auto-layout to blame?

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.

UIbutton deallocated in custom UITableViewCell

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)

Resources