I am experiencing a very strange crash, here is the backtrace.
* thread #1: tid = 0x2403, 0x3379516c CoreFoundation`CFHash + 8, stop reason = EXC_BREAKPOINT
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.
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.
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: