How can I update the view controller code when it hits the top of the view stack?

I have a viewController (Planner) that loads two view managers (InfoEditor and MonthlyPlan) when the application starts. MonthlyPlan is hidden behind InfoEditor (at boot).

So my question is when I exchange InfoEditor for MonthlyPlan (getting MonthlyPlan is brought to the top) how can I update the data in the MonthlyPlan view. The NSLog in viewDidLoad is called when the application starts (which makes sense.) The NSLogs in viewDidAppear and viewWillAppear do nothing.

Any ideas?

Thanks!

- Adding more details -

I myself create a hierarchy of views. A simple viewController that simply loads the other two viewControllers. Two child view managers load at the same time (when the application starts.) To exchange two views, I use this code:

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

The exchange of views is wonderful. The invalid part is just a way to tell subview you are ahead, update some properties.

+3
source share
2 answers

There are no details here. How do you "exchange" two species?

UINavigationController , viewWillAppear/viewDidAppear , / viewController. UINavigationController. UINavigationController, , .

- (void)viewWillAppear:(BOOL)animated

, / . SDK viewWillAppear;

, , . , , .

Update:

: , / , SDK. , //, (, UINavigationController), .

exchangeSubView, , , .

, , / viewWillAppear/viewWillDisappear .

.

// your top level view controller
-(void) switchActiveView:(UIViewController*)controller animated:(BOOL)animated
{
    UIController* removedController = nil;

    // tell the current controller it'll disappear and remove it
    if (currentController)
    {
        [currentController viewWillDisapear:animated];
        [currentController.view removeFromSuperView];
        removedController = currentController;
    }

    // tell the new controller it'll appear and add its view
    if (controller)
    {
        [controller viewWillAppear:animated];
        [self.view addSubView:controller.view];
        currentController = [controller retain];
    }

    // now tell them they did disappear/appear
    [removedController viewDidDisappear: animated];
    [currentController viewDidAppear: animated];
    [removedController release];
}
+5

updataData . , subView:

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
if (subView1IsActive) [subView1Controller updateData];
else [subView2Controller updateData];
0

Source: https://habr.com/ru/post/1702871/


All Articles