Jeremy Grenier
Jeremy Grenier

Reputation: 674

iOS: Detect when my UIView is add in other view

CustomView *customView = [...];
[self.view addSubview:customView];

I need to detect in my CustomView class when it is added in other views or when my superview changes.

Upvotes: 37

Views: 15288

Answers (3)

Hampus Nilsson
Hampus Nilsson

Reputation: 6822

You can use willMoveToSuperview: and didMoveToSuperview to detect when the view is moved around. layoutSubviews will be called when the superview changes frame.

Upvotes: 82

Peter
Peter

Reputation: 1109

  • For a UIView use - (void)didMoveToSuperview
  • For a UIViewController use -(void)viewWillAppear:(BOOL)animated

Upvotes: 7

Ashok Domadiya
Ashok Domadiya

Reputation: 1122

also assign THE TAG of Customview before addsubview and the detect by Particular TAG.

Upvotes: -5

Related Questions