简体   繁体   中英

Swift - ViewDidAppear called from another class

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?

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM