0

I am trying to update some of my views when they appear, so I naturally found myself using the viewDidAppear: and viewWillAppear: methods. However, I have experienced two problems with using these methods:

  1. When I only implement one of the methods, the changes that I am looking to make are not completely there, so in order for everything to work, I implemented both methods with the same code.
  2. Even after implementing both methods with the same code, there is a 0.5 to 1 second delay when updating the view's content.

Here is my code for my custom made table view controller:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.tableView reloadData];
}

For some reason, I must call the reloadData method twice to completely update my table view.

Here is my code for my custom made normal view controller:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    navItem.title = @"Name1";
    nameLabel.text = @"Name1";
    nameField.hidden = YES;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    navItem.title = @"Name1";
    nameLabel.text = @"Name1";
    nameField.hidden = YES;
}

Thank you!

bgottlob
  • 527
  • 2
  • 6
  • 14
  • you need to use only one method, it is strange that if you are using one then it's not working for you, is it always a issue for you? – rishi Apr 24 '12 at 11:59
  • This is the first time that I am using these methods, so I guess it always has been an issue for me. – bgottlob Apr 24 '12 at 12:05
  • just try using only viewWillAppear once again and put a breakpoint, then check if control is there or not? – rishi Apr 24 '12 at 12:06
  • also which method you are using to load the view - viewDidLoad or loadView or any other one? – rishi Apr 24 '12 at 12:07
  • have you tried debugging as well? Whether control came there? – rishi Apr 24 '12 at 12:10
  • Sounds weird. What does "... changes ... not completely there ..." mean? Is it only that some of the subviews/tableCells change while others keep the old value? I'd try different things now (cause I don't know the answer). 1. Test without impl of viewDidAppear, call super viewWillAppear:animated] at the end of the impl., NSLog to see if viewWillAppear got called. If fail try with viewDidDisappear instead of viewDidAppear, test with that impl alone, NSLog etc. ... just experiment. – Kai Huppmann Apr 24 '12 at 12:18
  • When I say that the changes are not completely there, I mean that only one or two of the changes were made. For example, on my table view, I need reloadData to add a new cell and set the text on its title label. However, implementing only one of the methods will add the cell, but replace it with an existing one. When I implement both methods, table view acts as expected. – bgottlob Apr 25 '12 at 00:32
  • I also tried to implement the other available methods in different ways, but the only methodology is the one that I previously used. – bgottlob Apr 25 '12 at 02:21

1 Answers1

1

You should only use the viewWillAppear method.

Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
Prabha
  • 424
  • 1
  • 4
  • 11