0

I have a view controller which get called from several places, and the first time it is called, awakeFromNib is called, but viewDidLoad is not called. viewWillAppear and viewDidAppear are called each time.

Also, the view (a UITableView subclass) functions correctly, except that anything within viewDidLoad is obviously not implemented.

loadView is not overridden in this view controller.

the code used to override viewDidLoad and awakeFromNib:

- (void)awakeFromNib
{
// Configure for self sizing cells:
 self.tableView.estimatedRowHeight = 44;
 self.tableView.rowHeight = UITableViewAutomaticDimension;

 self.tableView.allowsSelectionDuringEditing = YES;
 self.clearsSelectionOnViewWillAppear = NO;

 self.navigationItem.title = nil;
 self.navigationItem.rightBarButtonItem = nil;
 printf("\n awake from nib \n \n ---------- \n");
}

- (void)viewDidLoad
{
 [super viewDidLoad];
 self.navigationItem.rightBarButtonItem = self.editButtonItem;
 self.tableView.allowsSelectionDuringEditing = YES;
}

how is it possible that awakeFromNib is called but viewDidLoad is not, and how can I fix it?

edit: I received an answer that helped fixed it, however I would like to know why it happened, because it may be related to a bug in my app.

thank you.

9
  • Please add code for these methods. And the code also where the view is initialized. Commented Sep 24, 2015 at 8:08
  • @Rage added the code. the view controller is instantiated in many places as well as the storyboard, so i don't believe it is the problem
    – Nitzan R
    Commented Sep 24, 2015 at 8:17
  • 1
    I don't think it will resolve your issue but you should call [super awakeFromNib]; in your override. Commented Sep 24, 2015 at 8:18
  • @NitzanR If the view controller is instantiated in many places then it may exactly be the problem. It is possible viewDidLoad is called much earlier that the rest of the methods. Commented Sep 24, 2015 at 8:21
  • 1
    then the view is awoken before the vc, the vc's setView is called but as it hasn't been awoken, it doesn't call viewDidLoad yet but defers it till it is awaoken. and without the super call it never knows :) q.e.d. ;)
    – Daij-Djan
    Commented Sep 24, 2015 at 8:47

1 Answer 1

3

This was a bit of a stab in the dark in a comment but it turned out to resolve the issue.

Ensure to call [super awakeFromNib] in the overridden method.

1
  • 1
    the view is awoken before the vc, the vc's setView is called but as it hasn't been awoken, it doesn't call viewDidLoad yet but defers it till it is awaoken. and without the super call it never knows :) q.e.d. ;) -- explaining why this works
    – Daij-Djan
    Commented Sep 24, 2015 at 8:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.