1

I'm seeing a weird crash when I call [self.navigationController popViewControllerAnimated:YES]; in a delegate callback after selecting an item from a table view. No trace is printed to the console in Xcode - but this is the stack available in the system Console - any ideas?

Thread 0:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x94f5e332 __kill + 10
1   libsystem_kernel.dylib          0x94f5d932 kill$UNIX2003 + 32
2   CoreFoundation                  0x01c9876b CFHash + 43
3   CoreFoundation                  0x01c8f8b4 __CFDictionaryStandardHashKey + 36
4   CoreFoundation                  0x01cbce9c CFBasicHashRemoveValue + 1148
5   CoreFoundation                  0x01cca669 CFDictionaryRemoveValue + 185
6   Foundation                      0x011a3162 -[NSISEngine setIntegralizationAdjustment:forMarker:] + 50
7   Foundation                      0x011a97ec -[NSISEngine removeConstraintWithMarker:] + 651
8   Foundation                      0x011b388e -[NSLayoutConstraint _removeFromEngine:] + 277
9   UIKit                           0x00a80d36 -[UIView(UIConstraintBasedLayout) _layoutEngine_willRemoveLayoutConstraint:] + 64
10  UIKit                           0x005ac2ae __48-[UIScrollView _setAutomaticContentConstraints:]_block_invoke_0 + 181
11  Foundation                      0x011a8733 -[NSISEngine withAutomaticOptimizationDisabled:] + 57
12  UIKit                           0x00a80a5c -[UIView(UIConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 63
13  UIKit                           0x005ac1bb -[UIScrollView _setAutomaticContentConstraints:] + 122
14  UIKit                           0x005ac9ca -[UIScrollView _rememberDependentConstraint:] + 123
15  UIKit                           0x00a8ce60 ___updateViewDependenciesForConstraint_block_invoke_0 + 51
16  UIKit                           0x00a80cee _updateViewDependenciesForConstraint + 224
17  UIKit                           0x00a80bea -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 202
18  UIKit                           0x00a80da7 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 61
19  UIKit                           0x00594be4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 447
20  UIKit                           0x005a081f -[UIScrollView _didMoveFromWindow:toWindow:] + 65
21  UIKit                           0x0059505d -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1592
22  UIKit                           0x0059505d -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1592
23  UIKit                           0x005905e6 -[UIView(Hierarchy) _postMovedFromSuperview:] + 157
24  UIKit                           0x00596af4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1784
25  UIKit                           0x0058eeed -[UIView(Hierarchy) addSubview:] + 56
26  UIKit                           0x007c58a9 -[UINavigationTransitionView transition:fromView:toView:] + 513
27  UIKit                           0x007c56a0 -[UINavigationTransitionView transition:toView:] + 55
28  UIKit                           0x00641c61 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2344
29  UIKit                           0x00641eab -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
30  UIKit                           0x006433d6 _popViewControllerNormal + 280
31  UIKit                           0x00643675 -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:] + 449
32  UIKit                           0x0c53b780 -[UINavigationControllerAccessibility(SafeCategory) _popViewControllerWithTransition:allowPoppingLast:] + 143
33  UIKit                           0x00642625 -[UINavigationController popViewControllerAnimated:] + 57

Update

I'm pretty sure this is an internal auto-layout issue like the one posted here: Strange Crash when dismissing view controller, auto-layout to blame?

I guess I'll just switch back to struts and springs.....

Community
  • 1
  • 1
Ted Tomlinson
  • 773
  • 2
  • 7
  • 18
  • I think the problem is with this [self.navigationController popToViewController:self animated:YES]; // you have used the self as view controller i.e you are poping your presentviewcontroller . If you want to popyour view controller try to do this [self popToViewController:vc animated:YES]; – SRI Aug 23 '13 at 05:55
  • It may be helpful http://stackoverflow.com/questions/5753256/poptoviewcontroller – SRI Aug 23 '13 at 05:55
  • pls check the layout constraint in the .xib file it should be unchecked this may cause the problem – Arun Aug 23 '13 at 05:57
  • How can you pop a Viewcontroller staying on the same viewcontroller? For instance how can you delete a folder while you are on that directory? – Exploring Aug 23 '13 at 06:03
  • this is a delegate callback - I'm using popToViewController: self to bring the current vc to the top of the stack. Note that this follows the typical list->detail delegate pattern where the listView (in this case the calling view) instantiates a detail view, sets itself as the delegate and pushes it onto the navigation stack. Then when the detail view completes it calls its delegate, which tells the navigation controller to pop back to itself. Note that I still see the bug using [self.navigationController popViewController animated: YES] – Ted Tomlinson Aug 23 '13 at 06:08
  • @ArunThiru - what do you mean 'it should be unchecked' - I'm using autolayout and I agree the stack trace suggests a layout constraint issue, but what should I be looking for? – Ted Tomlinson Aug 23 '13 at 06:09
  • Fine you have implemented a delegate. But `self` always points to current instance where is your control now. – Exploring Aug 23 '13 at 06:17
  • @TedTomlinson i thought your not using the auto layout constraint but the logs are showing that it related to layout constraint – Arun Aug 23 '13 at 06:22
  • @TedTomlinson try like that [[[[[UIApplication sharedApplication] delegate] window] rootViewController].navigationController popToRootViewControllerAnimated:YES]; – Arun Aug 23 '13 at 06:43

4 Answers4

4

You are trying to cut the branch of tree by standing on it :)

If you want to pop the view controller which is currently displaying on the screen. You can simply do this:

[self.navigationController popViewControllerAnimated:YES];
Muhammad Zeeshan
  • 2,441
  • 22
  • 33
  • Yeah - I used to have that code and I still saw the crash - note that I am calling popToVc... from inside a delegate *callback* so I am actually in the second vc below the top of the navigation stack. I've verified that the navigation stack looks correct prior to the call. This is some sort of issue with layout and view memory management I think. – Ted Tomlinson Aug 23 '13 at 06:14
  • @muhamad:yah..thats ri8..how can someone pop to self viewController.? – Preetam Jadakar Aug 23 '13 at 06:14
  • @TedTomlinson: does it still crash? – Preetam Jadakar Aug 23 '13 at 06:17
  • Can you post your code so that we can better understand the problem? – Muhammad Zeeshan Aug 23 '13 at 06:20
2

where ever you have called the delegate ,just after that you can call

[self.navigationController popViewControllerAnimated:YES]

to go to the previous controller,but if u have to go to different controller then get the reference of that controller and use

[self.navigationController popToViewController:referenceOfYourVC animated:YES]
Arun
  • 3,406
  • 4
  • 30
  • 55
Wizkid1490
  • 76
  • 3
2
[self.navigationController popViewControllerAnimated:YES]; 

Above code should not bring an error but wen you pop a view from the stack, the dealloc method of the view would automatically called. I believe you might have some memory related issues or you are releasing some zero retain count object in the dealloc method of the view.

MrWaqasAhmed
  • 1,479
  • 12
  • 12
0

Yep problem was some sort of bug/issue with auto-layout. I'm not sure what is is, but I've run into this issue elsewhere with system added controls (like the cancel button on a UISearchBar). I Converted the whole project to struts and it works with all the same code.

I'll wait until auto-layout's been around a bit longer before converting back.

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

Community
  • 1
  • 1
Ted Tomlinson
  • 773
  • 2
  • 7
  • 18