my didAddSubview
is not being called.
This is what I am doing.
In my viewController
- (void)viewDidLoad {
[super viewDidLoad];
SomeView *view = [[SomeView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
[self.view addSubview:view];
}
Where my SomeView
is a UI view (.h file)
#import <UIKit/UIKit.h>
@interface DyteMeetingView : UIView
@end
in which I have didAddSubview
like this
- (void)didAddSubview:(UIView *)subview{
[super didAddSubview:subview];
[self someFunc];
}
I placed debugger in didAddSubview
but the debugger never reaches here and hence [self someFunc];
is also not called.
Since didAddSubview
is a lifecycle method for UI view, I am also not calling it from anywhere.
Can someone help me in figure out the concept I missed out on/what I could be doing wrong?
PS: I don’t have any xib file for UIView.
PS: Intentionally added swift tag as well since there isn’t large chunk of code and I am confident that swift developers would be able to understand the question/code and might be able to help me out.
2
Answers
didAddSubview
inSomeView
will be called when a sub view is added to an instance ofSomeView
, but that isn’t what you are doing here. You are adding aSomeView
as a subview of another view.You want
didMoveToSuperview
; in this method you can use thesuperview
property ofself
to identify the view that it moved to.The
didAddSubview
will be called inviewController.view
, instead of yourSomeView
, because you usingviewController.view.addSubview(subview)