0

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?

Marcus
  • 9,032
  • 11
  • 45
  • 84

2 Answers2

1

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.

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58
  • I have not implemented viewWillAppear. I've also never heard of it. I'll look it up – Marcus Dec 09 '14 at 10:37
  • 1
    Sorry. I meant 'viewDidAppear' the method which is being called. Edited my answer. In any case you must learn about all the view controller lifecycle methods. – Swapnil Luktuke Dec 09 '14 at 10:43
  • The solution was that I could easily accomplish the task by making them separate view controllers (not child, parent). This eliminated the problem of calling the parent. Now to clean up my code – Marcus Dec 09 '14 at 10:49
0

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)

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
yashwanth77
  • 1,820
  • 1
  • 12
  • 17