Возможно, вы дважды использовали UIView, старый объект был сохранен superView.
например
UIView *viewA = [UIView new];
[superView addSubview:viewA];
viewA = [UIView new]; //there is a new object.
[superView addSubView:viewA];
другой пример, когда реализуются оба метода init
и initWithFrame
.
@interface MyView : UIView
@property (strong, nonatomic) UIView *subView;
@end
@implement MyView
- (instancetype)init {
self = [super init];
if (self) {
self.subView = [UIView new];
[self addSubview:self.subView];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.subView = [UIView new];
[self addSubview:self.subView];
}
return self;
}
@end
//init will call initWithFrame with CGRectZero automatically, subView alloced twice.
MyView myView = [[MyView alloc] init];