3

I am trying to understand the scenario of the method calls to view did/will appear and disappear.

What I did is selecting the table cell (higlights in grey) , go to detail view and go back and deselect the selected row (remove the selected cell grey color).

Here are my methods:

-(void)viewDidAppear:(BOOL)animated {
    DLog(@"%@ did appear", self);
    [super viewDidAppear:animated];

    if (_isPushed) {
        [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
        _isPushed=NO;
    }
}

-(void)viewWillAppear:(BOOL)animated {
    DLog(@"%@ will appear", self);
    [super viewWillAppear:animated];  //If I remove this super call , then it works fine and there is no delay in deselecting the table cell
}

-(void)viewWillDisappear:(BOOL)animated {
    DLog(@"%@ will disappear", self);
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    _isPushed=YES;
}

So , when I put breakpoint the flow goes like this:

without super call:

while pushing to new VC:

current viewWillDisappear    //makes sense
new viewWillAppear           //makes sense
current viewDidAppear         // doesnt make sense , y this should get called as the view is already appeared?
current viewWillDisappear     // make sense
current viewDidDisappear      //make sense
new viewDidAppear           //make sense

while coming back from pushed VC:

current viewWillDisappear
new viewDidDisappear
current viewDidDisappear
new viewDidAppear

with super call:

while pushing to new VC:

current viewWillDisappear
new viewWillAppear
current viewDidAppear
current viewWillDisappear
current viewDidDisappear
new viewDidAppear

while going back from pushed VC:

current viewWillDisappear
new viewDidDisappear
current viewDidDisappear
new viewDidAppear

The flow is pretty much the same either I use super call or not. But the problem I am facing is, when I use super call in viewWillAppear, there is a delay(around >1second) in deselcting the cell.

If I dont use the super call in viewWillAppear , there is no delay and the cell is deselcting (around <0.5 seconds)

I am not sure to use super call or not.

Can anyone please tell me why there is a delay in deselecting the cell?

Borys Verebskyi
  • 3,910
  • 6
  • 26
  • 37
Teja Nandamuri
  • 10,632
  • 6
  • 54
  • 95
  • If you are not adding any code do not bother with adding the method. Apple templates add potentially useful ["Boilerplate"](https://en.wikipedia.org/wiki/Boilerplate_code) methods, if you do not need them, that is do not need to add code to them, delete them. In this example you can just delete the methods: `viewWillAppear` and `viewWillDisappear`. – zaph Sep 15 '15 at 20:22

3 Answers3

6

Yes, the documentation states you must:

Discussion

This method is called before the receiver's view is about to be added to a view hierarchy and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with displaying the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. If you override this method, you must call super at some point in your implementation.

trojanfoe
  • 116,099
  • 18
  • 197
  • 233
1

Generally yes, call super. I've seen weird things happen in nav controllers when I forget.

In this case, if you have a UITableViewController, try using its clearsSelectionOnViewWillAppear flag to clear the selection for you.

Graham Perks
  • 21,623
  • 8
  • 56
  • 79
0

Yes It's necessary to write super.

bhautikmewada191
  • 645
  • 1
  • 8
  • 20