I am experiencing a very strange crash, here is the backtrace.
* thread #1: tid = 0x2403, 0x3379516c CoreFoundation`CFHash + 8, stop reason = EXC_BREAKPOINT
Based on idea of Carl Lindberg I prepared and used the following iOS category and I have no crash anymore:
UIView+AddSubviewWithRemovingFromParent.h
#import
@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:];
To sum it up: