0
votes

I am using this code for the navigation view controller in the start

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
splashViewController *rootVC = [[splashViewController alloc]initWithNibName:@"splashViewController" bundle:nil];
self.navigator = [[UINavigationController alloc] initWithRootViewController:rootVC];
self.window.rootViewController = self.navigator;
[self.window makeKeyAndVisible];

after that i am using this simple method to push to next view

ScoreboardListViewController *SLvc = [[ScoreboardListViewController alloc]initWithNibName:@"ScoreboardListViewController" bundle:nil];
[self.navigationController pushViewController:SLvc animated:YES];

and using this to pop out from the view

[self.navigationController popViewControllerAnimated:YES];

but when i poppet and again push to the same view with different property values then viewdidload method did not run

it only runs if i just to any other view and then push to this view

i was not able to understand this abnormal behaviour. as when ever i push to any view then this viewdidload should be executed.....

for example i am doing this to get to the view ->

SLvc.trigger = @"sold";
SLvc.lblHeader.text = value;
[self.navigationController pushViewController:SLvc animated:YES];

-> then i popped out by back button by using this

[self.navigationController popViewControllerAnimated:YES];

-> then i push to the same view with different property

 SLvc.trigger = @"earning";
SLvc.lblHeader.text = value;
[self.navigationController pushViewController:SLvc animated:YES]

and this time viewdidload didn't run.

4
Show me the code where you are again pushing the same Viewcontroller with Different Property - Muhammad Waqas Bhati
Are you pushing the same instance or are you creating a new instance of slvc? - Fogmeister
hello thanks for the reply.....i had updated my question with exect values ...kindly check - Parv Bhasker

4 Answers

2
votes

This is because you are holding a strong pointer to SLvc controller. When you pop it, the view controller is retained. Initializing a new controller every time you push will solve your problem.

2
votes

// below method called when pop out from the view

- (void)viewWillAppear:(BOOL)animated
{

    [super viewWillAppear:animated];
}
1
votes

You can try these in your viewcontroller:

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    // your code here
}

or

-(void)awakeFromNib
{
   [super awakeFromNib];
   // your code here
}

viewDidLoad() -Called after init(coder:) when the view is loaded into memory.

Similar to viewWillAppear, this method is called just before the view disappears from the screen. And like viewWillAppear, this method can be called multiple times during the life of the view controller object. It’s called when the user navigates away from the screen – perhaps dismissing the screen, selecting another tab, tapping a button that shows a modal view, or navigating further down the navigation hierarchy

0
votes

viewDidLoad is called exactly once, when the ViewController is first loaded into the memory. This is where you want to instantiate any instance variables and build any views that live for the entire lifecycle of this ViewController. However, the view is usually not yet visible at this point.

However, viewWillAppear gets called every time the view appears.