Как выполнить метод после удаления из супервизора - PullRequest
0 голосов
/ 03 декабря 2011

У меня есть UIViewController (назовите его SubUIVC), который был загружен через мой основной UIViewController (назовите его MainUIVC) с помощью моего метода showNewView, и когда я закончу с SubUIVC, я возвращаюсь в MainUIVC с помощью моего метода goBack.

Что я хотел бы сделать, так это выполнить некоторый код в MainUIVC после завершения метода goBack и загрузки моего MainUIVC.view.

Может кто-нибудь помочь мне с этим? Ниже приведены два метода, на которые я ссылался выше.

-(void) showNewView:(UIViewController*)showView{    
UIView *currentView = self.view;

    // get the the underlying UIWindow, or the view containing the current view
    UIView *theWindow = [currentView superview];    
    UIView *newView = showView.view; 

    // remove the current view and replace with newView
    [theWindow addSubview:newView];

    // set up an animation for the transition between the views
    CATransition *animation = [CATransition animation];
    [animation setDuration:WIPE_ANIMATION_DURATION];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[theWindow layer] addAnimation:animation forKey:@"SwitchToNewView"];
}

-(IBAction)goBack:(id)sender{       
    UIView *currentView = self.view;

    // get the the underlying UIWindow, or the view containing the current view
    UIView *theWindow = [currentView superview];

    // remove the current view and replace with superview
    [currentView removeFromSuperview];

    // set up an animation for the transition between the views
    CATransition *animation = [CATransition animation];
    [animation setDuration:WIPE_ANIMATION_DURATION];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[theWindow layer] addAnimation:animation forKey:@"SwitchToNewView"];
}

1 Ответ

1 голос
/ 03 декабря 2011

Имейте свойство BOOL в MainController, чем значение get, установленное функцией goBack: *. 1001 *

В viewDidAppear: основного контроллера, проверьте этот BOOL, чтобы увидеть, было ли представление только что появилось в результате возврата: вызываетсяи делай свое дело.Очевидно, вы должны сбросить этот флаг.

...