Swift - ViewDidAppear called from another class

1.8k views Asked by At

I have a simple application with two views. When I launch to the home view the viewDidLoad and viewDidAppear are called. When I go to another view in my application it calls super.viewDidLoad and calls the func, but it also calls viewDidAppear from the home view. I can't find any commands to call it (Searched entire code base). What could be causing this extra call?

* ADDITIONAL TESTS *

I added break points to find the issue.

1) home calls: viewdidLoad, then viewdidappear

2) click link to detailview

3) this calls deatailview viewdidload which calls super (aka home) view did load

4) home view did load finishes and then home viewdidappear is called

5) error in home viewdidappear

Any ideas why home viewdidappear was called afterwards?

2

There are 2 answers

3
Swapnil Luktuke On BEST ANSWER

As you mentioned, 'home' is the super class of your 'detail' view controller " deatailview super (aka home) ". You either haven't implemented the viewDidAppear or called super.viewDidAppear in the 'detail' vc , hence the superclass' (home vc's) viewDidAppear is executed.

0
yashwanth77 On

Parent class Code

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
}

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
}

Child Class Code

- (void)viewDidLoad {

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
}

Explanation

Home class is super Class and Child class is sub class when ever super class view is loaded for the first time it calls viewDidLoad and viewDidAppear of super class. When we click on the link it moves to detail view there it calls viewDidLoad(sub class)->viewDidLoad(super class) and viewDidAppear(sub class)->viewDidAppear(super class)