0

So I have a view controller that displays some amount of data. When a user clicks on a button, they are taken to UITableViewController. I then have a "barbuttonitem" that uses
[self dismissViewControllerAnimated:YES completion:nil] to go back to the previous view controller with the data. The problem is that the data on the previous controller is supposed to change when I return back to it through a method I'm declaring in viewDidLoad. However, the data stays the same. Any idea why this could be?

For example: If the text label says "3 notifications", and the users clicks on the button to go to the UITableViewController and then clicks the back button, it is supposed to say 0 notifications.

Tulon
  • 4,011
  • 6
  • 36
  • 56
shreyashirday
  • 892
  • 1
  • 10
  • 34
  • viewDidLoad is only called once in the lifetime of a controller -- it will not be called again when you dismiss your modal controller. – rdelmar May 15 '14 at 21:45
  • so what is the solution? every time I try to create a segue from the barbuttonitem to the view controller, it says "unrecognized selector sent to instance" but im not sure why. – shreyashirday May 15 '14 at 21:47
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – herzbube May 15 '14 at 22:03

2 Answers2

0

You have to implement your logic in viewWillAppear. when you push a newViewController the oldViewController is still in memory but not in screen, viewWillAppear will be called when go back (back button)

-(void)viewWillAppear:(BOOL)animated{

    [self.tableView reloadData];
}
Idali
  • 1,023
  • 7
  • 10
0

You should use

- (void)viewDidAppear:(BOOL)animated

Instead of

- (void)viewDidLoad

viewDidLoad is called one time, when the view controller is loaded the first time. viewDidAppear is called every time your view is displayed at the hierarchy.

Barbara R
  • 1,057
  • 5
  • 18